Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录后如何在刀片页面Laravel 5.8中显示用户详细信息_Laravel_Model View Controller_Laravel Blade_Laravel 5.8 - Fatal编程技术网

登录后如何在刀片页面Laravel 5.8中显示用户详细信息

登录后如何在刀片页面Laravel 5.8中显示用户详细信息,laravel,model-view-controller,laravel-blade,laravel-5.8,Laravel,Model View Controller,Laravel Blade,Laravel 5.8,我想检查用户类型并在刀片页面上显示名称。这是数据库 我希望如果键入_user=1并使用Auth:check id进行验证,然后打印VTPL Administration,然后键入_user=2&3 我将如何在blade页面中查看它 这是刀片页 这是我的用户模型 错误 控制器代码 请帮帮我 @dump(Auth::user()->type_user); @if(Auth::check()) {{Auth::user()->name???'} @恩迪夫 模型中的更改 namesp

我想检查用户类型并在刀片页面上显示名称。这是数据库

我希望如果键入_user=1并使用Auth:check id进行验证,然后打印VTPL Administration,然后键入_user=2&3

我将如何在blade页面中查看它

这是刀片页

这是我的用户模型

错误

控制器代码

请帮帮我

@dump(Auth::user()->type_user);
@if(Auth::check())
{{Auth::user()->name???'}
@恩迪夫
模型中的更改

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminUserLogin extends Authenticatable {
    
    use Notifiable;
   
protected $table = 'user';
protected $fillable = [
    'name',
    'email',
    'password',
    'status',
    'type_user',
];
protected $casts = [
    'type_user' => 'integer',
    'status' => 'integer',
];
protected $hidden = [
    'password',
    'remember_token',
    'created_at',
    'updated_at'
];}

希望它能帮助您轻松完成。

您可以在
应用程序/模型/用户
模型中定义一个附加字段
键入用户名
获取用户名

class User extends Authenticatable
{
    use Notifiable;

    protected $appends = ['type_user_name'];

    public function getTypeUserNameAttribute()
    {
        $type_user = $this->attributes['type_user'];
        
        if ($type_user == 1) return "VTPL Administration";
        if ($type_user == 2) return "User 2";
        if ($type_user == 3) return "User 3";
    }

}

所以,无论何时查询
auth()->user()
,都会填充
type\u user\u name
字段。

数据库中已经提到了这一点,我只想在登录后用type\u user检查auth:check(),然后显示name。就这样。我已经附上了用户模型。现在可以了吗?请检查我是否已附加错误页@webzar@AbhijitDutta你试过上面的代码吗?它不起作用。我添加了代码,但它不起作用我不理解你的回复兄弟。它不起作用…Auth::check()中得到了什么?它什么也不显示…如果你登录,那么它就起作用了,因为它从我这边完全起作用。它什么也不返回。。。。每当我在@if(Auth::check())下放置一个div时,该div就会消失,这意味着该函数不工作,它是否与Laravel 8一起工作
public function authCheck() {
    $input = Request::all();
    $rule = array(
        'email' => 'required|exists:users',
        'password' => 'required'
    );
    $validation = Validator::make($input, $rule, array());
    if ($validation->fails()) {
        $messages = $validation->errors();
        return Redirect::back()->withInput()->withErrors($messages);
    }
    $cred = [
        'email' => $input['email'],
        'password' => $input['password'],
    ];
    Auth::attempt($cred, true);
    if (Auth::check()) {
        $user_type = Auth::User()->type_user;
        if ($user_type == 1) {
            return redirect()->to('/adminlogin');
        } else {
            return redirect()->to('/dashboard');
        }
    } else {
        $message = 'Username or password is incorrect';
        return Redirect::back()->withInput()->with('error', $message);
    }
}
namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminUserLogin extends Authenticatable {
    
    use Notifiable;
   
protected $table = 'user';
protected $fillable = [
    'name',
    'email',
    'password',
    'status',
    'type_user',
];
protected $casts = [
    'type_user' => 'integer',
    'status' => 'integer',
];
protected $hidden = [
    'password',
    'remember_token',
    'created_at',
    'updated_at'
];}
class User extends Authenticatable
{
    use Notifiable;

    protected $appends = ['type_user_name'];

    public function getTypeUserNameAttribute()
    {
        $type_user = $this->attributes['type_user'];
        
        if ($type_user == 1) return "VTPL Administration";
        if ($type_user == 2) return "User 2";
        if ($type_user == 3) return "User 3";
    }

}