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

Php make a component in laravel 10

How to create component in Laravel 10 ?

March 23, 2023March 16, 2024

In this tutorial i will show you simple html based component in Laravel 10 using blade. Creating reusable components is a fundamental aspect of modern web development, as it allows developers to simplify code and improve efficiency. Laravel 10, one of the most popular PHP frameworks, comes with a robust…

Read More
Laravel Create database connection in laravel

How to make database connection in Laravel 8 ?

December 14, 2021February 22, 2024

Laravel comes with first party support for several database drivers. Laravel gives much better flexibility in terms of using the RDBMS based databases. Laravel supports MySQL, PostgreSQL, SQLite and SQL Server by default but if you want to make connection with Mongo or other database then you need to install…

Read More
Php How to Use Broadcast to Send Web Socket Event in Laravel

How to Use Broadcast to Send Web Socket Event in Laravel ?

June 23, 2022June 26, 2022

Broadcasting is used to send real time message to client. In this article we will learn to use broadcast to send web socket event in laravel. Web sockets are used to communicate with client from server for real time communication. Broadcasting very useful to send update to client when any…

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

  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version