php - Why Am I Able to Use user() method in laravel, without even defining it -
i have usercontroller , user model in laravel 5 source. there 1 authcontroller present (shipped prebuilt laravel source).
i query data db in blades making use of eloquent models.
however, neither in user model (eloquent ) nor in of controller, user() method defined. then, use in blade accessing auth class. why?
for example,
in blade, {{ auth::user()->fname }} works. retrieve data fnamefrom users table , echo it.
what logic behind it, , can emulate same other db tables such tasks?
whenever automatically or manually this
if (auth::attempt(['email' => $email, 'password' => $password])) { } the selected user's data stored in storage/framework/sessions
it have data like
a:4:{s:6:"_token";s:40:"pekgolhoxml1rudnnq2bese1isttskylffihuozu";s:9:"_previous";a:1:{s:3:"url";s:43:"http://localhost/learnings/laravel5/laravel";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1432617607;s:1:"c";i:1432617607;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}} the above sessions file doesn't have data , have data such user's id, url, token in json format.
then whenever call {{ auth::user()->fname }} laravel recognises you're trying fetch logged in user's fname laravel fetch file , user's primary key , refer user's table database. , can coloumns of users table have.
you can learn more here
Comments
Post a Comment