我正在使用Laravel 5.5,我有一个``发布''模型。在该模型中,我想使用路由参数(例如userId)。在Post Controller中有此ID。
public function getPosts($userId)
{
$posts = Post::latest()->paginate(8);
return Response::json($posts);
}
Run Code Online (Sandbox Code Playgroud)
我想在Post Model中使用$ userId来获取更多信息。如何从Post模型访问此参数?我应该使用会话存储userId值并尝试使用它吗?还有其他办法吗?