我有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