我有兩個網址的一個類別和一個品牌,如:同樣的路線,但在Laravel 5.1調用不同的控制器路由
http://localhost/project/womens-fashion #category
http://localhost/project/babette-clothes #brand
我只是想一個路線,但調用不同的控制器。 我已經寫了路線,但它不適合我的發送錯誤。請參見下面的代碼:
<?php
use \DB;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\Redirect;
Route::get('/','[email protected]');
Route::get('/product', array('uses' => '[email protected]'));
Route::get('/{slug}', function($slug) {
$result = DB::select('SELECT controller FROM url_setting where slug = ?', [$slug]);
if ($result[0]->pw_us_controller == '[email protected]') {
return Redirect::action('[email protected]', array($slug));
} elseif ($result[0]->pw_us_controller == '[email protected]') {
return Redirect::action('[email protected]', array($slug));
} else {
return Redirect::action('[email protected]');
}
});
錯誤:InvalidArgumentException in UrlGenerator.php line 576: Action App\Http\Controllers\[email protected] not defined.
我很困惑,什麼地方出了錯?任何想法!!!
顯然,你沒有一個函數'視圖()'在'CategoryController'。 – Jerodev
我在我的類CategoryController中有函數視圖()。如果我使用此路由:Route :: get('/ {slug}','CategoryController @ view') - > where('slug','[A-Za-z-0-9] +');它正確路由 – okconfused
路由並不是要執行這樣的邏輯,你可以做的是從路由獲取/發佈單個函數上的數據,然後根據傳遞的數據將數據轉移到不同的函數中。 –