Laravel 5:laravel 5中没有IF输出

问题描述 投票:0回答:2

laravel 5中没有IF输出。

失败

dd(Auth::User()->id)

输出:0

2.成功

dd(Auth::User()->email)

输出:[email protected]

其他一切都运作良好。 id不打印。

尝试

应用程序/ HTTP /控制器/认证/ LoginController.php

public function username(){
    return 'id';
}

用户迁移

Schema::create('users', function (Blueprint $table) {
        $table->increments('xid');
        $table->string('platform')->default('site'); 
        $table->smallInteger('level')->default('0'); 
        $table->string('id')->unique();
        $table->string('email');
        $table->string('password'); 
        $table->string('name'); 
        $table->string('school_name');
        $table->string('school_code'); 
        $table->integer('money')->default('0'); 
        $table->smallInteger('access')->default('0'); 
        $table->string('phone');
        $table->integer('buy_count')->default('0'); 
        $table->integer('law_count')->default('0'); 
        $table->rememberToken(); 
        $table->timestamps(); });

用户模型

 protected $fillable = [
    'school_name','school_code','name', 'id', 'password','phone'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

dd结果

#original: array:16 [▼
"xid" => 1
"platform" => "site"
"level" => 2
"id" => "testid"
"email" => "[email protected]"
"password" => "$2y$10$exeC0AGystAtLI3mdFbdYu1aWzGc6GEv/12DnMjjqCHKABqM2DfSO"
"name" => "test"
"school_name" => "test"
"school_code" => "S010000599"
"money" => 0
"access" => 1
"phone" => "01011112222"
"buy_count" => 0
"law_count" => 0
"remember_token" => "KQvgIRjp35Y9RA8hY1K2b7zMbnnk0gTFO3x1k8SIkPq4dwXoG98cAOnv4ViZ"
"created_at" => "2018-02-21 14:06:26"
"updated_at" => "2018-02-24 22:43:51"
laravel laravel-authorization
2个回答
0
投票

您始终可以使用id()方法:

auth()->id()

要么:

\Auth::id()

0
投票

尝试使用此功能

Auth::user()->id
© www.soinside.com 2019 - 2024. All rights reserved.