我對這種情況非常困惑。我有兩個資源名稱的路線。路由用戶角色Laravel 5.4
Route::resource('product', 'Product\AreaManagerProductController');
Route::resource('product', 'Product\SystemAdminProductController');
我需要把它作爲一個,因爲我有一個上下文綁定。
$this->app->when(AreaManagerProductController::class)
->needs(ProductInterface::class)
->give(AreaManagerProductRepository::class);
$this->app->when(SystemAdminProductController::class)
->needs(ProductInterface::class)
->give(SystemAdminProductRepository::class);
上下文綁定工作正常......但我需要改變我的這樣的路線。
Route::resource('product_area_manager', 'Product\AreaManagerProductController');
Route::resource('product_system_admin', 'Product\SystemAdminProductController');
我創建ProductController
和某種奇怪的解決方案。
public function index(){
//Create a conditional statement base on user
return app('App\Http\Controllers\Product\AreaManagerProductController')->index();
}
它可能工作,但它不會觸發中間件......對這種情況最好的做法是什麼? TY
你不應該有你的路線相同的名稱'路線::資源('產品','產品\ AreaManagerProductController');'喜歡的產品。你應該使用不同的路線 –
@NikhilRadadiya說..你不能聲明兩個同名的路線..你可以做的是將控制器擴展到另一個.. Route :: resource('product', 'Product \ AreaManagerProductController');'然後在你的AreaManagerProductController中可以做到,'類AreaManagerProductController擴展SystemAdminProductController' – Demonyowh
我知道它不會與兩個相同的名稱路由資源工作...我會嘗試擴展'ProductController'和看看我能不能做到。謝謝。 – Rbex