I want to get my authenticated $userId as a value in an html element from the moment the function is executed (from the moment the user logs in) and place it in an input element in index.html
my AuthorizedAccessTokenController.php
class AuthorizedAccessTokenController
{
public function getUser(Request $request)
{
//this is the key I want to place in my input
$userId = $request->user()->getKey();
return $userId;
}
}
this is the input in my index.html
<input type="text" value="the $userId">
To get authenticated user's ID you can use id()
method with auth()
helper or Auth
facade:
<input type="text" value="{{ auth()->id() }}">
Or:
<input type="text" value="{{ Auth::id() }}">
echo '<input type="text" value="' . $userid . '">';
Put this inside the function where you get the User ID
In PHP you can prepend the $
before the name of the function inside the string. This should do what you are looking for:
<input type="text" value="$getUser($REQUESTVARIABLE)">
It seems a method of a class so you have to call it properly with your object instance