我有问题资源和答案资源。从问题索引我希望在每个问题下面都有一个链接,称为答案,点击时会将您带到创建答案表单。要回答的问题的id需要传递给answers.create方法,然后创建创建答案视图,并将问题id作为隐藏字段。
这里是问题索引的相关部分
@foreach($questions as $question)
{{ $question->question }} </br>
{{ HTML::linkRoute('medicalanswers.create', 'Answer', $question->id) }}
@endforeach
这会创建一个像这样的链接
http://localhost:8888/medicalanswers/create?2
而不是
http://localhost:8888/medicalanswers/create/2
这是第一个问题,但即使我手动输入该链接,我也会从路由中获得一个notfoundhttpexception
这是我的答案控制器方法
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create($qid)
{
return View::make('medicalanswers.create')
->with('questionid', $qid);
}
和我的routes.php文件
Route::get('/', array('as' => 'home', function()
{
return View::make('layouts.default');
}));
Route::get('users/login', 'UsersController@getLogin');
Route::get('users/logout', 'UsersController@getLogout');
Route::post('users/login', 'UsersController@postLogin');
Route::resource('users', 'UsersController');
Route::resource('images', 'ImagesController');
//routes related to images
Route::post('images/toalbum/{id}', array('as' => 'imgToAlbum', 'uses' => 'ImagesController@addImageToAlbums'));
Route::resource('videos', 'VideosController');
Route::resource('albums', 'AlbumsController');
Route::resource('measurements', 'MeasurementsController');
Route::resource('medicalquestions', 'MedicalquestionsController');
Route::resource('medicalanswers', 'MedicalanswersController');
答案 0 :(得分:1)
创建新路线解决了问题
Route::get('medicalanswers/create/{qid}', array('as' => 'createanswer', 'uses' => 'MedicalAnswersController@create'));