我有2种途径与他们的方法写在同一个控制器[LinkController]:路由优先级顺序
Route::get('/{country}/{category}', ['as' => 'tour.list', 'uses' => '[email protected]']);
Route::get('/{category}/{slug}',['as' => 'single.tour', 'uses' => '[email protected]']);
而且我的方法是:
public function tourlist($country, $category)
{
$tour = Tour::whereHas('category', function($q) use($category) {
$q->where('name','=', $category);
})
->whereHas('country', function($r) use($country) {
$r->where('name','=', $country);
})
->get();
return view('public.tours.list')->withTours($tour);
}
public function singleTour($slug,$category)
{
$tour = Tour::where('slug','=', $slug)
->whereHas('category', function($r) use($category) {
$r->where('name','=', $category);
})
->first();
return view('public.tours.show')->withTour($tour);
}
我的视图代码是:
<a href="{{ route('single.tour',['category' => $tour->category->name, 'slug' => $tour->slug]) }}">{{$tour->title}}</a>
我遇到的麻烦是第二条路线[single.tour]返回第一条路线[tour.list]的视图。我试图在第二种方法中返回其他视图,但仍返回第一种方法的视图。 laravel有路由优先权吗?
烨,后者将优先考虑http://stackoverflow.com/questions/20870899/order-of-route-declarations-in-laravel-package – SteD