Php 类别';auth';在某些视图中找不到

Php 类别';auth';在某些视图中找不到,php,laravel,Php,Laravel,我将此代码放在标题布局中,从users表中获取一个字段 <li class="tophe"> Your ID is : {{auth::user()->shenase}} </li> 有什么问题吗?您应该将其用作Auth或Auth(): 您的ID是:{{auth()->user()->shenase} 或: 您的ID是:{{Auth::user()->shenase} 希望对您有所帮助。在laravel中,有一个身份验证帮助程序,您可以使用它获取有

我将此代码放在标题布局中,从users表中获取一个字段

<li class="tophe">
Your ID is :   {{auth::user()->shenase}}
</li>

有什么问题吗?

您应该将其用作
Auth
Auth()

  • 您的ID是:{{auth()->user()->shenase}
  • 或:

  • 您的ID是:{{Auth::user()->shenase}

  • 希望对您有所帮助。

    在laravel中,有一个身份验证帮助程序,您可以使用它获取有关当前经过身份验证的用户的所需信息,您可以这样使用它:

    <li class="tophe">
    Your ID is :   {{auth()->user()->someAttribute}}
    </li>
    // not auth alone it's a function
    
  • 您的ID是:{{auth()->user()->someAttribute}
  • //不仅仅是身份验证它是一个函数
  • 您的ID是:{{\illumb\Support\Facades\Auth::user()->shenase}

  • 您可以尝试使用“为身份验证类提供绝对路径”

    请根据实际要求修改您的答案。
    <li class="tophe">
    Your ID is :   {{auth()->user()->someAttribute}}
    </li>
    // not auth alone it's a function
    
    <li class="tophe">
    Your ID is : {{\Illuminate\Support\Facades\Auth::user()->shenase}}
    </li>