如題, 確認$role
是獲取成功的,可以列印出具體資料,但是會觸發throw Error
, return
的值是null
.
有人遇到過類似問題嗎,求解
public static function findByName(string $name, $site_id = null, $guardName = null): RoleContract
{
$guardName = $guardName ?? Guard::getDefaultName(static::class);
if (is_null($site_id))
$site_id = self::getUser()->site_id ?? 0;
$role = static::where('name', $name)->where('guard_name', $guardName)
->where('site_id', $site_id)->first();
if (! $role) {
throw RoleDoesNotExist::named($name);
}
return $role;
}
Role {#689
+guarded: array:1 [
0 => "id"
]
#connection: "mysql"
#table: "roles"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [
"id" => 608
"site_id" => 270
"name" => "Editor"
"guard_name" => "web"
"created_at" => "2019-06-18 11:04:54"
"updated_at" => "2019-06-18 11:04:54"
"remarks" => "編輯"
]
#original: array:7 [
"id" => 608
"site_id" => 270
"name" => "Editor"
"guard_name" => "web"
"created_at" => "2019-06-18 11:04:54"
"updated_at" => "2019-06-18 11:04:54"
"remarks" => "編輯"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
-permissionClass: null
}