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










share|improve this question



















  • 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














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










share|improve this question



















  • 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












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










To get the currently authenticated user's ID, use
Auth::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.






share|improve this answer






















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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, use
Auth::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.






share|improve this answer






















  • 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














up vote
0
down vote



accepted










To get the currently authenticated user's ID, use
Auth::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.






share|improve this answer






















  • 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












up vote
0
down vote



accepted







up vote
0
down vote



accepted






To get the currently authenticated user's ID, use
Auth::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.






share|improve this answer














To get the currently authenticated user's ID, use
Auth::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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党