Laravel8でnamespace()を利用すると発生するエラー。
App\Providers\RouteServiceProviders.php
<?php namespace App\Providers; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\Route; class RouteServiceProvider extends ServiceProvider { /** * The path to the "home" route for your application. * * This is used by Laravel authentication to redirect users after login. * * @var string */ public const HOME = '/home'; + protected $namespace = 'App\Http\Controllers';
protected $namespace = ‘App\Http\Controllers’;を追加する
読み込ませる
$ composer dumpa
<?php use Illuminate\Support\Facades\Route; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); // 訪問者情報取得ツール Route::prefix('your-info')->group(function () { Route::namespace('YourInfo')->group(function () { Route::get('/', 'UserAgentController@show'); }); });
routeが表示されて読み込まれた!
src $ php artisan route:list +--------+----------+-----------+------+--------------------------------------------------------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+-----------+------+--------------------------------------------------------+------------+ | | GET|HEAD | / | | Closure | web | | | GET|HEAD | api/user | | Closure | api | | | | | | | auth:api | | | GET|HEAD | your-info | | App\Http\Controllers\YourInfo\UserAgentController@show | web | +--------+----------+-----------+------+--------------------------------------------------------+------------+