Support the ongoing development of Laravel.io →
Authentication
Last updated 1 year ago.
0

Try Auth::user()['id'] or Auth::user()['user_id']

0

Just get rid of those brackets. id or location are properties that you can return, not some methods.

$userId = Auth::user()->id;

$userLocation = Auth::user()->location;

Althought I'd suggest you to always use helper function if there is one available. In this case you can use **auth()**function like this:

$userId = auth()->user()->id;

$userLocation = auth()->user()->location;
Last updated 7 years ago.
0

And how do I receive userId in the controller?

# requires login
Route::group(['middleware' => 'auth'], function(){

	# create customer
	Route::post('/createcustomer', [
		'uses' => 'ChannelCustomer@createCustomer',
		'as' => 'createCustomer',
		'userId' => Auth::user()->id
	]);
});
0

Sign in to participate in this thread!

Eventy

Your banner here too?

muppbarn muppbarn Joined 29 Mar 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.