Search code examples
laravelapieloquentlaravel-passport

Laravel + Passport api get records by Auth


Problem is i want to take records by Auth::user()->department How to solve this problem in Laravel api + Passport.

"message": "Class 'App\Http\Controllers\API\Auth' not found",

Controller/Api/ApiController.php

public function index(){
$banks = Bank::where('bank', Auth::user()->department)->orderby("created_at",'desc')->get();
   return $this->sendResponse($banks->toArray(), 'Амжилттай уншигдлаа.');
}

Solution

  • That's it, You just need to add Auth Class in your php file.

    use \Auth;