How in laravel route to put all get requests for one action?
1 answer
If for api routes, in routes / api.php , for example:
Route::get('/{any}', 'MyController@myAction')->where('any', '.*'); If for web routes, in routes / web.php , for example:
Route::get('/{any}', 'MyController@myActio')->where('any', '^(?!api).*$'); // before the any was: ".*" The expression means .* Means any route, and ^(?!api).*$ Means any routes but which do not start api
If instead of ^(?!api).*$ Was also .* , Then this would not work in api routes:
Route::fallback(function() { return response()->json(['message' => 'Route not Found!'], 404); }); |