mercredi 25 juillet 2018

accessing custom method in model

Im practicing laravel and im making a custom method for my user

In my user model i have build a function like this

public function employee(){
    return $this->where('user_type','employee');
}

and then in my controller I'm accessing the function like this

public function index(){
     $users = User::latest()->employee();
     return ProductsResource::collection($users);
}

but it return an error Method Illuminate\Database\Query\Builder::employee does not exist.how to fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire