我希望从执行函数的那一刻起(从用户登录的那一刻起)将经过身份验证的$ userId作为html元素中的值,并将其放在index.html的输入元素中
我的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;
}
}
这是我的index.html中的输入
<input type="text" value="the $userId">
答案 0 :(得分:0)
要获取经过身份验证的用户ID,您可以使用id()
方法与auth()
帮助程序或Auth
外观:
<input type="text" value="{{ auth()->id() }}">
或者:
<input type="text" value="{{ Auth::id() }}">
答案 1 :(得分:0)
echo '<input type="text" value="' . $userid . '">';
将此内容放在您获得用户ID
的功能中答案 2 :(得分:0)
在PHP中,您可以在字符串中的函数名称前加$
。这应该做你想要的:
<input type="text" value="$getUser($REQUESTVARIABLE)">
它似乎是一个类的方法,因此您必须使用对象实例
正确调用它