Fix Array to string conversion In RouteFileRegistrar.php Laravel
In Laravel you may encounter such errors:
or
Illuminate\Routing\Router::loadRoutes(): Failed opening required 'Array' (include_path='.:/usr/share/php')
or
ErrorException: Array to string conversion
This is because of the routes are grouped with group()
method and there are some mistakes in the group definition.
You cannot use a mixed format of grouping routes like:
Route::prefix('auth')
->group([
'namespace'=>'Auth',
],function ()
as you see the first argument of the “group” method is an array that it also can include the “prefix”, while I extracted it outside of the “group” method and it brings this error.
Solution:
Organize your grouped routes!
Configure and group the routes like below will solve your issue.
Route::group(
[
'namespace'=>'Auth',
'middleware'=>'api',
'prefix' => 'auth',
'as'=> 'user.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');
});
I would like to introduce two packages for Laravel that I have recently developed: Laravel Pay Pocket, a modern multi-wallet package, and Laravel Failed Jobs, a UI for the Laravel Failed Jobs Table. I hope they may be of help to you.
https://github.com/HPWebdeveloper/laravel-pay-pocket
https://github.com/HPWebdeveloper/laravel-failed-jobs