如果您願意冒險嘗試,您一定會受益於資源控制器(http://laravel.com/docs/4.2/controllers#restful-resource-controllers)。採用這些之後,您的詳細意見都會看
public function show($id) {...}
和你的編輯的觀點都會像
public function edit($id) {...}
和路由會或多或少手柄本身。
假設你已經採用了這種慣例,你可以在基礎控制器中放置一些通用邏輯,並讓你的獨立控制器擴展它們。
一種基站控制器可以有這樣的東西:
<?php
use Illuminate\Routing\Controller as Controller;
class BaseController extends Controller
{
/**
* Returns the routable action string for editing this resource
* @return string
*/
final protected function getEditAction()
{
return __CLASS__ . '@edit';
}
/**
* Returns the routable action string for showing this resource
* @return string
*/
final protected function getShowAction()
{
return __CLASS__ . '@show';
}
}
然後,延長你的基本控制器控制器,你可以做這樣的東西:
// Redirect to the detail page upon save
return Redirect::action($this->getShowAction());
// Pass a link to the detail page into a view
return View::make('foo.bar', ['back_url' => URL::action($this->getShowAction())]);
等。
我沒有使用RESTful路由。這看起來不是我的答案,但我可能會錯過一些東西。 我正在尋找的是這樣的: 用戶開/發票/ 1 /明細,點擊編輯到/聯繫人/ 9 /編輯,點擊保存或取消,返回到/發票/ 1 /明細 或 用戶在/任務/ 2 /詳細信息,點擊編輯到/聯繫人/ 9 /編輯,點擊保存或取消,回到/任務/ 2 /詳細 – user3720435 2014-09-23 01:49:25