2014-11-15 210 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

相關問題