Problems using array parameters on Route::group()
Hey there,
I'm having problems using parameters like 'middleware' on Route::group() facade static method,
And using param 'middleware' like this:
Route::group(['middleware' => 'role:admin'], function () {
Route::post('create','AppointmentController@create');
});
The error message is:
Symfony\Component\Debug\Exception\FatalErrorException: Illuminate\Routing\Router::loadRoutes(): Failed opening required 'Array' (include_path='.:/usr/share/php')
I'm aware that we can circumvent this problems by using middleware() on each post/get/method, but i was looking for a solution to avoid code duplication.
I've got the "same" problem, now what you are looking for seems to work, but I tried to do:
Route::name('admin.')->group(['middleware' => 'role:admin'], function () {
Route::post('create','AppointmentController@create');
});
and this fails... while it should works I guess. ref
I am having the same problem
Hello, I ran into this problem. Though I could have used middleware for each GET/POST... but to avoid code duplication I refactored my code from
//Client Side of the Application
Route::namespace('Clientside')->group(['middleware' => 'defaultdata'],function () {
// Controllers Within The "App\Http\Controllers\Backoffice" Namespace
Route::get('/', 'indexController@index');
Route::get('/hotel_searches/show', 'SearchController@search_hotel');
});
to
//Client Side of the Application
Route::namespace('Clientside')->group(function () {
Route::middleware(['defaultdata'])->group(function(){
// Controllers Within The "App\Http\Controllers\Backoffice" Namespace
Route::get('/', 'indexController@index');
Route::get('/hotel_searches/show', 'SearchController@search_hotel');
});
hope it helps someone.
Hello, I ran into this problem. Though I could have used middleware for each GET/POST... but to avoid code duplication I refactored my code from
//Client Side of the Application Route::namespace('Clientside')->group(['middleware' => 'defaultdata'],function () { // Controllers Within The "App\Http\Controllers\Backoffice" Namespace Route::get('/', 'indexController@index'); Route::get('/hotel_searches/show', 'SearchController@search_hotel'); });to
//Client Side of the Application Route::namespace('Clientside')->group(function () { Route::middleware(['defaultdata'])->group(function(){ // Controllers Within The "App\Http\Controllers\Backoffice" Namespace Route::get('/', 'indexController@index'); Route::get('/hotel_searches/show', 'SearchController@search_hotel'); });hope it helps someone.
What about refactoring it to this:
//Client Side of the Application
Route::group(['namespace'=>'Clientside', 'middleware'=>'defaultdata'], function () {
// Controllers Within The "App\Http\Controllers\Backoffice" Namespace
Route::get('/', 'indexController@index');
Route::get('/hotel_searches/show', 'SearchController@search_hotel');
});
Got that idea from the best answer from the discussion here.
PS: I haven't tested using namespace in a group array out but am guessing it would work since prefix and middleware work.
I am getting this error when I change
Route::group([
to
Route::namespace( 'Auth' )->group([
even though this is what the documentation suggests.
Full code:
Route::namespace( 'Auth' )->group([
'middleware' => 'api',
'prefix' => 'auth'
], function ($router) {
Route::post('register', 'AuthController@register');
Route::post('login', 'AuthController@login');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');
});
@paddelboot add the namespace to the group, I think that will solve it...
Try this:
Route::group(['namespace'=>'Auth', 'middleware'=>'api', 'prefix' => 'auth'], function () {
Route::post('register', 'AuthController@register');
Route::post('login', 'AuthController@login');
Route::post('logout', 'AuthController@logout');
Route::post('refresh', 'AuthController@refresh');
Route::post('me', 'AuthController@me');
});