TuxxyDOS
TuxxyDOS

Reputation: 195

Laravel 5.4 - Use column-sortable

I'm trying to use column-sortable for my laravel 5.4 (https://github.com/Kyslik/column-sortable),

My model :

    class InfoBird extends Model
{
    public $timestamps = false;
    protected $primaryKey = "id_oiseau";
    protected $table = "oiseau";

    use Sortable;

    public $sortable = [ 
        'nom_codifie',
        'nom_commun',
        'etat_actuel',
        'pays',
        'date_reception',
        'date_renvoi',
        'immatriculation',
        'nom_local'
    ];

    public function getBirds() {
        $birds = DB::table('oiseau as oi')
            ->leftJoin('local_lpo', 'oi.id_local_lpo', 'local_lpo.id_local_lpo');

        return $birds;
    }
 }

My controller :

public function birds() {

        $infoBirds = new InfoBird;
        $birds = $infoBirds->getBirds();

        $birds = $birds->sortable()->paginate(15);

        //$birds = InfoBird::sortable()->paginate(15);

        return view('pages.birds', compact('birds'));
    }

It was working before i add the model ( there was only the sentence in comment ). But now i have this eror :

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

I'am running out of idea to fix that, i appreciate your help !

Upvotes: 0

Views: 2978

Answers (1)

Amarnasan
Amarnasan

Reputation: 15529

getbirds() returns a QueryBuilder, so you are trying to access to the sortable method of a QueryBuilder (which does not exist), instead of the sortable method of the model Infobird (which does exist).

Try this:

    $info = Infobird::sortable()->leftjoin('local_lpo', 'oi.id_local_lpo', 'local_lpo.id_local_lpo')->paginate(15);
    return view('pages.birds', compact('birds'));

Upvotes: 2

Related Questions