Search code examples
phplaravellaravel-5.3

BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::makeAllSearchable()


I am trying to run the command php artisan scout:import "App\User" to import user records into search driver as per documentation (Laravel 5.3 Scout Documentation). I keep getting [BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::makeAllSearchable() as an error. Why am I getting this error? I have included the searchable trait in my users controller and added the scout class to my app/config providers array, so I am struggling to see why the method doesn't exist...


Solution

  • You should not add the trait to the controller but to the model. So in your case to App\User.php

    <?php
    
    namespace App;
    
    use Laravel\Scout\Searchable;
    use Illuminate\Database\Eloquent\Model;
    
    class User extends Model
    {
        use Searchable;
    }