讨论数量:
<?php
$user = Auth::guard (‘api’)->user ();
dd($user);
// 打印输出的是
/*
App\Models\User {#1359 ▼
#fillable: array:3 [▶]
#hidden: array:2 [▶]
#casts: array:1 [▶]
#connection: "mysql"
#table: "users"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▶]
#original: array:8 [▶]
#changes: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
}
*/
由此可以看出属于模型。模型从数据库查询得到的数据,所以获得的数据是从数据库的到的。
你可以看看 Laravel 中使用 JWT 认证的 Restful API
第一次获取从数据库检索数据并缓存起来,之后再获取将直接返回