Laravel | Auth::user()->id isn't working in AppServiceProvider
up vote
0
down vote
favorite
I can get the Auth ID when i put it in any controller with
Auth::user()->id
But when i put it in AppServiceProvider.php , it returns `Trying to get property 'id' of non-object
i don't understand why ?
Eddit : I tried this but still not working
public function boot()
view()->composer('*', function ($view)
if (Auth::check())
$id=Auth::user()->id;
$idd=Person::where('user_id','=',$id)->get('photo');
$view->with('idd', $idd );
$view->with('id', $id );
);
Error :
Argument 1 passed to IlluminateDatabaseGrammar::columnize() must be of the type array, string given, called in
laravel
add a comment |
up vote
0
down vote
favorite
I can get the Auth ID when i put it in any controller with
Auth::user()->id
But when i put it in AppServiceProvider.php , it returns `Trying to get property 'id' of non-object
i don't understand why ?
Eddit : I tried this but still not working
public function boot()
view()->composer('*', function ($view)
if (Auth::check())
$id=Auth::user()->id;
$idd=Person::where('user_id','=',$id)->get('photo');
$view->with('idd', $idd );
$view->with('id', $id );
);
Error :
Argument 1 passed to IlluminateDatabaseGrammar::columnize() must be of the type array, string given, called in
laravel
4
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
How are you authenticating the user?
– HCK
Nov 10 at 17:46
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I can get the Auth ID when i put it in any controller with
Auth::user()->id
But when i put it in AppServiceProvider.php , it returns `Trying to get property 'id' of non-object
i don't understand why ?
Eddit : I tried this but still not working
public function boot()
view()->composer('*', function ($view)
if (Auth::check())
$id=Auth::user()->id;
$idd=Person::where('user_id','=',$id)->get('photo');
$view->with('idd', $idd );
$view->with('id', $id );
);
Error :
Argument 1 passed to IlluminateDatabaseGrammar::columnize() must be of the type array, string given, called in
laravel
I can get the Auth ID when i put it in any controller with
Auth::user()->id
But when i put it in AppServiceProvider.php , it returns `Trying to get property 'id' of non-object
i don't understand why ?
Eddit : I tried this but still not working
public function boot()
view()->composer('*', function ($view)
if (Auth::check())
$id=Auth::user()->id;
$idd=Person::where('user_id','=',$id)->get('photo');
$view->with('idd', $idd );
$view->with('id', $id );
);
Error :
Argument 1 passed to IlluminateDatabaseGrammar::columnize() must be of the type array, string given, called in
laravel
laravel
edited Nov 10 at 21:22
asked Nov 10 at 17:33
yassine j
698
698
4
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
How are you authenticating the user?
– HCK
Nov 10 at 17:46
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16
add a comment |
4
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
How are you authenticating the user?
– HCK
Nov 10 at 17:46
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16
4
4
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
How are you authenticating the user?
– HCK
Nov 10 at 17:46
How are you authenticating the user?
– HCK
Nov 10 at 17:46
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
To get the currently authenticated user's ID, useAuth::id();
Another case may be that there is not a current user, in which case Auth::user()
is returning NULL. Wrap the code in a
if (Auth::check())
// Do stuff
to make sure there is a user logged in.
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
To get the currently authenticated user's ID, useAuth::id();
Another case may be that there is not a current user, in which case Auth::user()
is returning NULL. Wrap the code in a
if (Auth::check())
// Do stuff
to make sure there is a user logged in.
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
add a comment |
up vote
0
down vote
accepted
To get the currently authenticated user's ID, useAuth::id();
Another case may be that there is not a current user, in which case Auth::user()
is returning NULL. Wrap the code in a
if (Auth::check())
// Do stuff
to make sure there is a user logged in.
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
To get the currently authenticated user's ID, useAuth::id();
Another case may be that there is not a current user, in which case Auth::user()
is returning NULL. Wrap the code in a
if (Auth::check())
// Do stuff
to make sure there is a user logged in.
To get the currently authenticated user's ID, useAuth::id();
Another case may be that there is not a current user, in which case Auth::user()
is returning NULL. Wrap the code in a
if (Auth::check())
// Do stuff
to make sure there is a user logged in.
edited Nov 10 at 21:18
answered Nov 10 at 21:10
Daniel Chen
446
446
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
add a comment |
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
Still not working..
– yassine j
Nov 10 at 21:11
Still not working..
– yassine j
Nov 10 at 21:11
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
Edited the answer, do you have a current user?
– Daniel Chen
Nov 10 at 21:19
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
I edited post again with a new error message, can you check please ?
– yassine j
Nov 10 at 21:23
Thank you it's works now.
– yassine j
Nov 10 at 21:25
Thank you it's works now.
– yassine j
Nov 10 at 21:25
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241615%2flaravel-authuser-id-isnt-working-in-appserviceprovider%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
possible duplicate: stackoverflow.com/questions/37372357/…
– nakov
Nov 10 at 17:38
How are you authenticating the user?
– HCK
Nov 10 at 17:46
Possible duplicate of Laravel - How to get current user in AppServiceProvider
– Marwelln
Nov 10 at 18:53
Hello, thank you for ur interest. I saw the duplicate question and i eddited post for you. Still not working. Can you help please ?
– yassine j
Nov 10 at 21:16