Simply put your Route::get('/{page}','MainController@getPage');
last. That way if it finds another route before it will use it but if it doesn't then it will get caught by this. For example:
Route::get('/welcome','WelcomeController@getWelcome');
Route::get('/test','TestController@getTest');
Route::get('/{page}','MainController@getPage');
If you were to hit /welcome
or /test
it should route them to the correct controller. If you where to hit /hello
it should go to the MainController
and hit function getPage($page)
with $page
being the page you hit.
If it hits MainController@getPage
you know it was basically a 404.
If you need to know before you hit the route for some reason you could create something like this:
Route::get('/checkurl/{page}',function($page) {
$exists = Route::has('/' . $page);
return (new Response(json_encode(['exists'=>$exists]),200);
});