rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.77k stars 331 forks source link

Undefined method Builder::search() #206

Closed AEK-BKF closed 3 years ago

AEK-BKF commented 3 years ago

Hello, First, I'd like to thank you for this awesome package. I'm trying to run this example : https://github.com/rappasoft/laravel-livewire-tables#example-table In search, I get this error : BadMethodCallException, Call to undefined method Illuminate\Database\Eloquent\Builder::search()

rappasoft commented 3 years ago

The search scope for your model is up to you to define, it is not built into the package.

rappasoft commented 3 years ago

For example, here's one of mine for my users table that I put on my User model:

public function scopeSearch($query, $term)
{
    return $query->where(
        fn ($query) => $query->where('name', 'like', '%'.$term.'%')
            ->orWhere('email', 'like', '%'.$term.'%')
    );
}
AEK-BKF commented 3 years ago

Ah Ok ! Thanks, I thought you're using a search package.

nguillaumin commented 3 years ago

This was not immediately clear to me either, it may be worth giving an example of an actual SQL query in the docs like you did above.

bdelamatre commented 3 years ago

Hey guys, I am working on a merge request to add some default search behavior like existed previously. Maybe it will help with confusion by allowing you to choose between a manual implementation or an out-of-box search implementation.

rappasoft commented 3 years ago

I'll make it more clear in the docs.

bdelamatre commented 3 years ago

If this is approved: https://github.com/rappasoft/laravel-livewire-tables/pull/210/files

You would be able to use ->searchable() on columns like before. Of course, you would still be able to implement search as @rappasoft indicates and that may be more flexible for your needs.