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 Laravel whereHas

Laravel whereHas in eloquent Model Example

October 2, 2022March 16, 2024

In this blog post, we’ll take a look at Laravel whereHas in eloquent Model Example and advantages. whereHas method is an important part of the Eloquent ORM. It allows you to add a constraint to a relationship query. whereHas method can be used to filter records based on a relationship….

Read More
Laravel How to use Post Ajax Request in Laravel 8 9

How to use Post Ajax Request in Laravel 8 / 9?

June 2, 2022June 2, 2022

Post Ajax request in laravel is use to communicate with server without reloading the page. Ajax requests are useful when we do not want to refresh the page and update the content of page so in that case Ajax request are very useful. Sometimes its also useful while submitting a…

Read More
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

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