I am having issues grabbing the currently authenticated user in Laravel 5.3. More specifically, I am making a HTTP request to my api.php file, which has the route defined as api/test/create.
The controller code:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Test; class TestController extends Controller { public function store(Request $request) { $this->validate($request, [ 'test_name' => 'required', 'youtube_id' => 'required', 'is_live_test' => 'required', ]); //Laravel 5.3 allows to get the user via request $user = $request->user; if($user) { return 'We are logged in'; } else { return 'We are not logged in'; } return ''; } } Every time it returns 'We are not logged in'. To test this out, I referenced {{ Auth::check() }} in my blade file, and that returns as '1'. I am not quite sure why the Controller does not recognize the user is logged in; any ideas?
I have tried different variations of referencing the authentication, including importing the Facade and doing Auth::check(), Auth::user(), but it brings the same result regardless.
$request->user()and you need to make sure the route uses theauthmiddlewareapimiddleware should haveauth:apiapiroutes, you need to setup passport: laravel.com/docs/5.3/passport