I have my own method in route.php file in Laravel 5.2. It works but when I try to run tests on phpunit this message appear:
Fatal error: Cannot redeclare getRoutes() (previously declared in C:\(...)\ppm\app\Httpoutes.php:55) in C:\(...)\ppm\app\Httpoutes.php on line 76
In Laravel 5.2, changing require
to require_once
in App/Providers/RouteServiceProvide.php
fixed the problem.
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require_once app_path('Http/routes.php');
});
}
I ran into the same problem today. I fixed it by assigning a closure
to a variable. Something like this:
$getRoutes = function(){
Route::get(...);
// ...
}
Route::group(["middleware" => ["auth"]], $getRoutes);
i get the same problem,i fixed by use function_exists(),like
if (!function_exists('getRoutes')) {
function getRoutes($modules)
{
foreach ($modules as $module) {
$actions = $module->getActions();
$route = $module->getRoute();
Route::get("/" . str_plural($route), ["as" => str_plural($route), "uses" => ucfirst($route) . "Controller@getList"]);
Route::get("/" . $route . "/find/{search_phrase?}", ["as" => $route . ".search", "uses" => ucfirst($route) . "Controller@getSearchJSON"]);
if ($actions["add"]) {
Route::get("/" . $route . "/create", ["as" => $route . ".create", "uses" => ucfirst($route) . "Controller@getAddForm"]);
Route::post("/" . $route . "/create", ["as" => $route . ".store", "uses" => ucfirst($route) . "Controller@getAddRequest"]);
}
if ($actions["edit"]) {
Route::get("/" . $route . "/edit/{id}", ["as" => $route . ".edit", "uses" => ucfirst($route) . "Controller@getEditForm"]);
Route::post("/" . $route . "/edit/{id}", ["as" => $route . ".update", "uses" => ucfirst($route) . "Controller@getEditRequest"]);
}
if ($actions["delete"]) {
Route::delete("/" . $route . "/delete/{id}", ["as" => $route . ".delete", "uses" => ucfirst($route) . "Controller@postDelete"]);
}
}
}
}