Support the ongoing development of Laravel.io →
Authentication

When a user is logged in, I bet Laravel has a clever way of showing whats in the database row for the specific user-id, yea?

For example, if email address luciannakarell@gmail.com is logged in, how do I extract the user id and the location, if the rows for the information is id and location?

Is it like

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

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

What auth classes do I need to namespace in, and where in the documentation can I read about it?

Last updated 2 years 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 8 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.

© 2025 Laravel.io - All rights reserved.