我有两种类型的内容,我希望它们可以在相同的 url 级别访问。
- 页面:
- mysite.com/about
- mysite.com/contact
- 类别:
- mysite.com/category-1
- mysite.com/category-2
我想根据特定的内容类型路由到控制器的方法。知道我该如何处理吗?
我的代码...
Route::get('{slug}', function($slug) {
$p = Page::where('slug', $slug)->first();
if (!is_null($p)) {
// How i can call a controller method here?
} else {
$c = Category::where('slug', $slug)->first();
if (!is_null($c)) {
// How i can call a another controller method here?
} else {
// Call 404 View...
}
}
});