Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Target class controller does not exist in Laravel

Target class controller does not exist in laravel 8 or Laravel 9

Aman Jain, August 20, 2022March 16, 2024

Target class controller does not exist in laravel 8 or laravel 9 error encounters in laravel versions above 8 because Before laravel 8 we can call controller without full namespace but after laravel 8, laravel team has changed the way to call the controller class. In laravel 5 and 6 we can call without specify the namespace but in laravel 8 and 9 you either need to call full namespace or you can import the class as follow

Route::get('/articles', 'App\Http\Controllers\ArticleController@index');

And another way is to assign the namespace in group as follow


Route::group(["namespace"=>"\App\Http\Controllers"],function(){
    Route::get('articles3', 'ArticleController@showArticle');
});

In this way way we created a group of routes using route group method and assigned the namespace.

we can also include controller and then can call method of it directly as follow

<?php
use App\Http\Controllers\ArticleController;
use Illuminate\Support\Facades\Route;

Route::get('/articles', [ArticleController::class,"index"]);

Here index is the method name and ArticleController::class is the name of controller class which use as use App\Http\Controllers\ArticleController;

Laravel has changed the way to call the routes in laravel 8 and laravel. if you used the previous way to call the controller then it will throw error like Target class controller does not exist since in laravel 8 or 9 it is required to define the namespace.

So to overcome from this exception of Target class controller does not exist in laravel 8 or laravel 9 we need to call it above way.

Last method if you want the same behavior as laravel 5, laravel 6 and laravel 7 then you can open the app/Providers/RouteServiceProvider.php class and uncomment the protected $namespace = 'App\\Http\\Controllers'; as follow

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;

class RouteServiceProvider extends ServiceProvider
{
    ... 
    protected $namespace = 'App\\Http\\Controllers';

    ...
}

I hope this will help you a lot to resolve the issue of Target class controller does not exist in laravel 8 or Laravel 9

You can also read : What is Laravel 8 middleware ?

Related

Php Laravel Laravel 9 classerrorlaravelroute

Post navigation

Previous post
Next post

Related Posts

Laravel Get Specific Columns Using with() function in laravel

How to get specific columns using with function in laravel ?

November 8, 2023March 16, 2024

When working with Laravel, a popular PHP framework, you’ll often need to retrieve specific columns using with() function in laravel from your database tables. Laravel provides a powerful and efficient way to do this using the with() function. This function allows you to specify which related models and their columns you want…

Read More

how to add multiple select in laravel eloquent ?

December 29, 2021February 22, 2024

Laravel eloquent builder has rich features to modify the query. In some cases we wanted to add multiple select in laravel and modify the select statement on basis of few conditions and wanted to add some select statement on condition. so in this article we will learn to add multiple…

Read More
Php How to drop foreign key in laravel migration

How to drop foreign key in laravel migration ?

September 28, 2022March 16, 2024

Drop foreign key to existing table are easy as creating a foreign key and adding columns to it. In laravel migration we can drop foreign key in laravel migration to existing table using dropForeign method of migration class. Major difference between creating new table and updating new table is Schema::create…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Mapping Together: The Vibrant Spirit of OpenStreetMap Japan
  • Understanding High Vulnerabilities: A Deep Dive into the Weekly Summary
  • Building a Million-Dollar Brand: The Journey of Justin Jackson
  • Mastering Schedule Management with Laravel Zap
  • The Resilience of Nature: How Forests Recover After Fires
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version