2014-11-15 171 views
1

我通过从数据库获取数据创建了一个动态页面。从laravel的动态页面链接到另一个页面

实施例:example.com/post/SE12

是动态创建的这/SE12。现在我在这个页面中有一个按钮,我想编辑帖子。

example.com/post/SE12/edit

如何使用laravel将按钮链接到此页面?以及如何路由此页面并在控制器中调用它?

在route.php

Route::resource('posts','PostsController'); 
    Route::get('/posts/{code}', [ 'as'=>'post-show', 'uses'=>'[email protected]']); 

回答

3

routes.php文件:

Route::get('post/{code}/edit', [ 'as'=>'post-edit', 'uses'=>'[email protected]']); 

控制器:

public function edit($id) 
{ 
    echo $id; //this will give the code. e.g. SE12 
} 

查看:

<a href="{{route('post-edit',[$post->id])}}">some title </a> 

N.B.你同时是resource controllermanual mapping。尽可能地坚持任一个。否则路线会发生冲突。

+0

谢谢!这工作。 – user1012181

+0

另外,如果我想更新此页面,该怎么办? 我给了'{{Form :: open(['url'=>'posts /'.$ code。'/ update'])}}'在表单和路由中:'Route :: get('/ ('code'/ update',''as'=>'post-update','uses'=>'PostsController @ update']);' and in controller 'public function update($ code) {''''''返回'完成'; }' 但它不起作用 – user1012181

+0

你得到了什么错误? – itachi

相关问题