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 Append Query String to Route in Laravel

How to Append Query String to Route in Laravel ?

November 22, 2023March 16, 2024

In this guide, we’ll explore the methods and best practices on append query string to route in Laravel. One common requirement is appending query strings to routes, a task often encountered when dealing with dynamic data and user interactions. Understanding Query Strings and Routes in Laravel Before diving into the techniques,…

Read More
Php Understanding laravel request

Understanding Laravel request with example

November 17, 2021November 22, 2021

Laravel provides a own class to handle the request which is Illuminate\Http\Request. Request is used to retrieve the user input(GET and POST), cookies and files that was submitted during the request. Get the request in controller Current Request can be get retrieved in controller by injecting the dependency in controller…

Read More
Php How to Add Google reCAPTCHA in Laravel 9 8 7 6 5

How to Add Google reCAPTCHA in Laravel 9 / 8 / 7 / 6 /5 ?

March 11, 2022March 11, 2022

Google reCAPTCHA used widely in may websites, in laravel its easy to use with third party package. Captcha is used to enhance the security of form. By adding the Captcha in laravel form we can prevent attackers to submit the form using the automated scripts and it adds an extra…

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

  • 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

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version