Skip to content

Instantly share code, notes, and snippets.

@vanchelo
Last active August 29, 2015 14:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanchelo/2164db7e0e4ffbb4f317 to your computer and use it in GitHub Desktop.
Save vanchelo/2164db7e0e4ffbb4f317 to your computer and use it in GitHub Desktop.
<?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');
@vanchelo
Copy link
Author

блок try {} catch () {} можно убрать и задать хендлер для отлова ошибок

App::error(function (Exception $e) { return $e->getMessage(); });

@vanchelo
Copy link
Author

Закоментированные строки это возможные варианты, но не все возможные)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment