Try this:
routes.php
Route::get('{slug}','CatsController@getCategory');
Route::get('{_slug}','ProductsController@getProduct');
BaseController : All Controllers should extends from this controller
class BaseController extends Controller{
// Add this function to BaseController
public function dispatch($controller, $params)
{
$controller = explode('@', $controller);
$method = array_pop($controller);
return call_user_func_array([\App::make($controller[0]),"{$method}"], $params);
}
}
CatsController.php
class CatsController extends BaseController{
//...
public function getCategory($slug)
{
// Find category by Slug
$category = Category::whereSlug($slug)->first();
// If category doesn't exists, then dispatch request to ProductController@getProduct
if(! $category)
{
return $this->dispatch('\ProductController@getProduct',$slug);
}
}
//...
}
ProductsController.php
class ProductController extends BaseController{
//...
public function getProduct($slug)
{
// Find product by Slug
$product = Product::whereSlug($slug)->first();
// If product doesn't exists, show 404 page
if(! $product)
{
App::abort(404);
}
}
//...
}
I hope this will helps