PHP

Target class [xxxxController] does not exist. Laravel8

Laravel

 

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        |
+--------+----------+-----------+------+--------------------------------------------------------+------------+

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)