简体   繁体   中英

Trying to get property 'id' of non-object Auth::user()->id in Controller Laravel?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM