我通过从数据库中获取数据创建了一个动态页面。
示例:example.com/post/SE12
此/SE12
是动态创建的。现在我在这个页面中有一个按钮,我想在其中编辑帖子。
example.com/post/SE12/edit
.
如何使用 laravel 将按钮链接到此页面? 以及如何路由此页面并在控制器中调用它?
在途中.php
Route::resource('posts','PostsController');
Route::get('/posts/{code}', [ 'as'=>'post-show', 'uses'=>'PostsController@show']);
routes .php:
Route::get('post/{code}/edit', [ 'as'=>'post-edit', 'uses'=>'PostsController@edit']);
控制器:
public function edit($id)
{
echo $id; //this will give the code. e.g. SE12
}
视图:
<a href="{{route('post-edit',[$post->id])}}">some title </a>
注意:你同时resource controller
和manual mapping
。 尽可能坚持其中任何一个。 否则路由将发生冲突。