Target class controller does not exist - Laravel 8



PHP Snippet 1:

use App\Http\Controllers\UserController;

Route::get('/users', [UserController::class, 'index']);
// or
Route::get('/users', 'App\Http\Controllers\UserController@index');

PHP Snippet 2:

public function boot()
{
    ...

    Route::prefix('api')
        ->middleware('api')
        ->namespace('App\Http\Controllers') // <---------
        ->group(base_path('routes/api.php'));

    ...
}

PHP Snippet 3:

// protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 4:

...
->namespace($this->namespace)
...

PHP Snippet 5:

Route::get('login', 'LoginController@login');

PHP Snippet 6:

Route::get('login', [LoginController::class, 'login']);

PHP Snippet 7:

protected $namespace = 'App\Http\Controllers';

PHP Snippet 8:

public function boot()
{
    $this->configureRateLimiting();

    $this->routes(function () {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/web.php'));

        Route::prefix('api')
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));
    });
}

PHP Snippet 9:

use App\Http\Controllers\InvoiceController; // InvoiceController is controller name

Route::get('invoice',[InvoiceController::class, 'index']);

PHP Snippet 10:

protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 11:

// Using PHP callable syntax...
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'index']);

PHP Snippet 12:

// Using string syntax...
Route::get('/', 'App\Http\Controllers\HomeController@index');

PHP Snippet 13:

// Using PHP callable syntax...
use App\Http\Controllers\HomeController;
Route::resource('/', HomeController::class);

PHP Snippet 14:

Route::get('register', 'Api\RegisterController@register');

PHP Snippet 15:

Route::get('register', [RegisterController::class, 'register']);

PHP Snippet 16:

use App\Http\Controllers\UserController;

Route::get('/user', [UserController::class, 'index']);

PHP Snippet 17:

use App\Http\Controllers\UserController;

Route::get('/users', [UserController::class, 'index']);

PHP Snippet 18:

action([UserController::class, 'index']);

return Redirect::action([UserController::class, 'index']);

PHP Snippet 19:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\RegisterController;


Route::get('/register',[RegisterController::class,'index'])->name('register');
Route::post('/register',[RegisterController::class,'store']);

Route::get('/', function () {
    return view('test.index');
});

PHP Snippet 20:

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()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));
    });
}

PHP Snippet 21:

protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 22:

protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 23:

Route::group(['namespace'=>'App\Http\Controllers', 'prefix'=>'admin',
 'as'=>'admin.', 'middleware' => ['auth:sanctum', 'verified']], function()
{
    Route::resource('/dashboard', 'DashboardController')->only([
        'index'
    ]);
});

PHP Snippet 24:

 /*
 * 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';

/**
 * The controller namespace for the application.
 *
 * When present, controller route declarations will automatically be prefixed with this namespace.
 *
 * @var string|null
 */
 // protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 25:

protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 26:

protected $namespace = 'App\\Http\\Controllers';

PHP Snippet 27:

Route::group(['namespace' => 'App\Http\Controllers\Api'], function () {
    Route::resource('user', 'UserController');
    Route::resource('book', 'BookController');
});

PHP Snippet 28:

php artisan route:clear

PHP Snippet 29:

Route::resource('homes', HomeController::class)->names('home.index');

PHP Snippet 30:

Route::middleware(null)->group(function () {
    Route::get('/some-path', [SomeController::class, 'search']);
});

PHP Snippet 31:

protected $namespace = 'App\\Http\\Controllers';