laravel 中将参数传递给控制器函数时出错
Error in passing argument to a controller function in laravel
我正在尝试将变量 $id 传递给路由文件中的控制器函数。
以下是各个文件的片段:
Routes.php
Route::get('/news-post/{$id}', 'BlogController@getPost');
BlogController.php
public function getPost($id)
{
$post = \App\blog::find($id);
if($post == NULL){
App::abort(404);
}
return View('webpages.news-post',['title'=>$post['title'],'post'=>$post]);
}
我在 RouteCollection.php 第 161 行收到 NotFoundHttpException:
我试过寻找原因,但找不到任何原因。
改变路线从
Route::get('/news-post/{$id}', 'BlogController@getPost');
至:
Route::get('/news-post/{id}', 'BlogController@getPost');
去掉路由中id前面的美元符号。检查 official documentation 中的示例。希望这有帮助。
我正在尝试将变量 $id 传递给路由文件中的控制器函数。
以下是各个文件的片段:
Routes.php
Route::get('/news-post/{$id}', 'BlogController@getPost');
BlogController.php
public function getPost($id)
{
$post = \App\blog::find($id);
if($post == NULL){
App::abort(404);
}
return View('webpages.news-post',['title'=>$post['title'],'post'=>$post]);
}
我在 RouteCollection.php 第 161 行收到 NotFoundHttpException:
我试过寻找原因,但找不到任何原因。
改变路线从
Route::get('/news-post/{$id}', 'BlogController@getPost');
至:
Route::get('/news-post/{id}', 'BlogController@getPost');
去掉路由中id前面的美元符号。检查 official documentation 中的示例。希望这有帮助。