我正在 Laravel 5.7 中构建应用程序。我在我的routes/api.php文件中设置了一个绑定到用户模型的路由。当我将现有用户 ID 传递到路由时,它被解析为空白用户模型。
我相信我已经通过在控制器中对用户模型进行类型提示来遵循 Laravel 标准。
路线/api.php
Route::prefix('role-permissions')->group(function () {
Route::get('by-user/{user}', 'RolePermissionsController@getByUserId')->name('api.role-permissions.by-user');
});
app/Http/Controllers/RolePermissionsController.php
public function getByUserId(User $user)
{
dd($user);
return $this->getAsResourceCollection($this->repository->getByUserId($user));
}
所述dd($user);返回空白User对象
预期:具有正确 ID 的填充用户模型我可以确认我的表中确实存在 ID 为 1 的用户
实际的:
User {#375
#fillable: array:3 [
0 => "name"
1 => "email"
2 => "password"
]
#hidden: array:2 [
0 => "password"
1 => "remember_token"
]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
#rememberTokenName: "remember_token"
#accessToken: null
}
慕姐8265434