我有两个网址的一个类别和一个品牌,如:同样的路线,但在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
路由并不是要执行这样的逻辑,你可以做的是从路由获取/发布单个函数上的数据,然后根据传递的数据将数据转移到不同的函数中。 –