Laravel:路线参数不起作用

时间:2018-05-08 17:23:58

标签: laravel

我今天将我的laravel项目切换到我的实时服务器,并且路由参数的类型提示不再起作用。正确识别参数,但只要我添加类型提示,我就会收到null。

存在id为1的帖子,我已经仔细检查过了,所以我假设某些服务器设置错误。

有人知道可能出现的问题吗?

路线:

Route::get('post/{post}', 'PostController@show');

服务器电话:

http://my-server/post/1

PostController中:

public function show(Post $post){
  dd($post); //null
}

public function show($post){
  dd($post); //1
}

1 个答案:

答案 0 :(得分:0)

尝试添加其他参数,例如$ id。由于show是默认的laravel函数,所以只需将其作为资源控制器路径或尝试以下方法方法

public function show(Post $post, $id){
  dd($id); //It will return the id
} 
相关问题