Reputation: 323
I have update Laravel from v5.7
to v5.8
and now my application doesn't run.
I updated it because of this issue: composer require rebing/graphql-laravel fails
I solved the packages incompatibility but now Laravel crashes:
$ php artisan serve
In Router.php line 366:
Argument 1 passed to Illuminate\Routing\Router::group() must be of the type array, string given, called in /var/www/masvino/Server-bak/vendor/laravel/framework/src/Illuminate/Support/Facades
/Facade.php on line 239
I suspect that the Laravel's team changed the firm of this method:
Illuminate\Routing\Router.php
/**
* Create a route group with shared attributes.
*
* @param array $attributes
* @param \Closure|string $routes
* @return void
*/
public function group(array $attributes, $routes) // line 366
{
$this->updateGroupStack($attributes);
// Once we have updated the group stack, we'll load the provided routes and
// merge in the group's attributes when the routes are created. After we
// have created the routes, we will pop the attributes off the stack.
$this->loadRoutes($routes);
array_pop($this->groupStack);
}
This is the current content of my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "^5.8.0",
"laravel/tinker": "^1.0",
"mll-lab/laravel-graphql-playground": "^1.1.0",
"nuwave/lighthouse": "^4.4.2",
"spatie/laravel-cors": "^1.6",
"webonyx/graphql-php": "^0.13.8",
"rebing/graphql-laravel": "2.1.1"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [],
"providers": [
"Rebing\\GraphQL\\GraphQLServiceProvider"
],
"aliases": {
"GraphQL": "Rebing\\GraphQL\\Support\\Facades\\GraphQL"
}
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
I think the problem could be in this file: app/Providers/RouteServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}
Don't know which is the correct format now for group()
method. Can anybody help me figure this out? Thanks in advance!
Upvotes: 6
Views: 14501
Reputation: 49
Upvotes: 0
Reputation: 872
same problem but i fixed it !
run composer update and then run php artisan route:clear and then use attributes before using route group function exemple:
Route::name('admin.')->group(function () {
Route::get('/dashboard', function () {
// Route assigned name 'admin.dashboard'...
})->name('dashboard');
});
Upvotes: 0
Reputation: 606
As the error message suggests, the problem is solved by adding an empty array into the web.php file.
Route::group([], function () {
Route::get('/', 'HomeController@index')->name('home');
});
And I am using Laravel v7.
Upvotes: 14
Reputation: 29
You can just use in your routes/web.php
Route::group( ['prefix' => 'backend','middleware' => ['auth', 'admin']], function() {}
Upvotes: 0