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?
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;
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
]);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community