問題 : 註冊,登入正常,跳轉後,Auth::user(); 獲取不到使用者例項
解決辦法:
public $incrementing = false;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'uuid';
/**
* The "type" of the auto-incrementing ID.
*
* @var string
*/
protected $keyType = 'varchar';
網上看的說是 $guard 不同的原因,dd後發現使用的都是‘web’的guard
檢視原始碼
namespace Illuminate\Auth;
trait Authenticatable{
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return $this->getKeyName();
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->{$this->getAuthIdentifierName()};
}
}
繼續追蹤
namespace Illuminate\Database\Eloquent;
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
{
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* The "type" of the auto-incrementing ID.
*
* @var string
*/
protected $keyType = 'int';
/**
* Get the primary key for the model.
*
* @return string
*/
public function getKeyName()
{
return $this->primaryKey;
}
}
果然,直接百度是不行的,還是檢視原始碼才是根本
本作品採用《CC 協議》,轉載必須註明作者和本文連結