laravel5中没有ID输出。
dd(Auth::User()->id)
输出:0
dd(Auth::User()->email)
输出:test@naver.com
其他一切运作良好。 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',
];
#original: array:16 [▼
"xid" => 1
"platform" => "site"
"level" => 2
"id" => "testid"
"email" => "test@naver.com"
"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"
答案 0 :(得分:0)
您始终可以使用id()
方法:
auth()->id()
或者:
\Auth::id()
答案 1 :(得分:0)
尝试使用此
Auth::user()->id