PHP code example of aw-studio / laravel-model-index

1. Go to this page and download the library: Download aw-studio/laravel-model-index library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aw-studio / laravel-model-index example snippets


class MyModel extends EloquentModel {

    use HasQueryIndex;

}


public function index(Request $request){
    MyModel::index()
            ->filterable(['name', 'age']
            ->get();
}

public function index(Request $request)
{
    // http://localhost?filter[popular]=true
    return User::index()
        ->filter('popular', fn($query, $value) => $query->popular())
        ->get();


    // http://localhost?filer[user.name]=John
    return Post::index()
        ->filter('user.name', function ($query, $value) {
            $query->whereHas('user', fn($query) => $query->where('name', $value));
        })
        ->get();
}

public function index(Request $request)
{
    return User::index()
        ->searchable(['name', 'email'])
        ->get();
}