Reputation: 325
I am trying to access Auth::user()->id but it's not working on Controller name BlogController
.Please note that controller exist in
namespace App\Http\Controllers\Admin\Blog
. I have mentioned Definition on top of Controller
use Auth; use Illuminate\Session\Middleware\StartSession;
on dd(Auth::Check())
return false. Please Help. Thanks
Upvotes: 0
Views: 1842
Reputation: 180147
Auth::user()
and Auth::check()
will return null
/false
(respectively) in two situations: if you're not logged in at all (for obvious reasons) or if your route doesn't have sessions or API token authentication enabled.
In a default install, the web
routes get session-based authentication, and the api
routes get token-based authentication. Ensuring the route has the proper set of middleware (or custom middleware, if you're rolling your own authentication criteria) does the trick.
Upvotes: 2