PHP code example of karabinse / eloquent-searchable

1. Go to this page and download the library: Download karabinse/eloquent-searchable 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/ */

    

karabinse / eloquent-searchable example snippets


use Karabin\Searchable\Concerns\IsSearchable;

class User extends Authenticatable
{
    use HasFactory, HasRoles, IsSearchable, Notifiable;

    protected $searchable = [
        'name',
        'email',
        'posts.title'
    ];


use Karabin\Searchable\Filters\TermSearchFilter;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = QueryBuilder::for(User::class)
            ->allowedFilters([
                AllowedFilter::custom('search', new TermSearchFilter),
            ])
            ->paginate($request->query('limit', 10));

        return Inertia::render('User/Index', [
            'users' => UserData::collect($users),
        ]);
    }