当用户登录后,我发现该用户时,我会在屏幕上看到当前用户的所有属性。
$testing = $request->user();
dd($testing);
用户对象:
User {#596 ▼
#table: "users"
+primaryKey: "id"
#fillable: array:3 [▶]
#hidden: array:2 [▶]
#connection: "mysql"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:9 [▶]
#original: array:9 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
}
如果要使用任何属性在控制器方法中运行用户检查,如何从控制器访问#attributes
数组?
答案 0 :(得分:2)
您可以通过以下方式访问属性:
magic method __get()
:
$request->user()->yourAttribute;
或直接调用getAttribute
方法:
$request->user()->getAttribute('yourAttribute');