Last active
August 29, 2015 14:13
-
-
Save vanchelo/2164db7e0e4ffbb4f317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// routes.php | |
Route::any('{controller}.{action}', function ($controller, $action) | |
{ | |
try | |
{ | |
$controller = app(studly_case($controller) . 'Controller'); | |
if ( ! method_exists($controller, $action)) | |
{ | |
return app('DefaultController')->callAction('error', compact('controller', 'action')); | |
// return app('DefaultController')->missingMethod(); | |
// App::abort(); // И написать handler на App::error чтобы отлавливать Exceptions | |
} | |
return $controller->callAction($action, []); | |
//return call_user_func([$controller, $action]); | |
} | |
catch (Exception $e) | |
{ | |
return app('DefaultController')->callAction('error', compact('controller', 'action')); | |
// return app('DefaultController')->missingMethod(); | |
// App::abort(); // И написать handler на App::error чтобы отлавливать Exceptions | |
} | |
})->where('controller', '^[a-z]+$')->where('action', '^[a-z]+$'); | |
// Для тех марштуров которые не попадают под верхнее условие, возвращаем стандартный ответ | |
Route::any('{error}', 'DefaultController@error'); |
Закоментированные строки это возможные варианты, но не все возможные)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
блок
try {} catch () {}
можно убрать и задать хендлер для отлова ошибок