Reputation: 8726
I created a dynamic page by taking data from the database.
Example: example.com/post/SE12
This /SE12
is dynamically created. Now I have a button in this page where I want to edit the post.
example.com/post/SE12/edit
.
How can I link a button to this page using laravel? and how can I route this page and call it in controller?
In route.php
Route::resource('posts','PostsController');
Route::get('/posts/{code}', [ 'as'=>'post-show', 'uses'=>'PostsController@show']);
Upvotes: 1
Views: 5615
Reputation: 6393
routes.php:
Route::get('post/{code}/edit', [ 'as'=>'post-edit', 'uses'=>'PostsController@edit']);
Controller:
public function edit($id)
{
echo $id; //this will give the code. e.g. SE12
}
View:
<a href="{{route('post-edit',[$post->id])}}">some title </a>
N.B. you are resource controller
and manual mapping
at the same time. stick to either one as much as possible. otherwise routes will get conflict.
Upvotes: 3