Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Laravel 8 Target Class Controller Does Not Exist

laravel 8 target class controller does not exist

Posted on September 10, 2020December 15, 2022 By XpertPhp

In this tutorial, we will tell you how we can solve the target class controller does not exist in Laravel 8(laravel 8 target class controller does not exist). You know that Laravel 8 was released a few days ago. They modified the routing system a bit from the different version of Laravel.

In this example, we will solve the routing problem in Laravel 8, because there are no target class apphttpcontrollers. so we have two solutions. one is to use the class name in the route file and the second is to define the namespace in RouteServiceProvider.php.

use the class name in the route file

routes/web.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
 
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StudentController;
 
  
 
/*
 
|--------------------------------------------------------------------------
 
| Web Routes
 
|--------------------------------------------------------------------------
 
|
 
| Here is where you can register web routes for your application. These
 
| routes are loaded by the RouteServiceProvider within a group which
 
| contains the "web" middleware group. Now create something great!
 
|
 
*/
 
  
 
Route::get('/', function () {
 
    return view('welcome');
 
});
 
Route::get('/student', [StudentController::class, 'index']);
// or
Route::get('/student', 'App\Http\Controllers\StudentController@index');

define the namespace in RouteServiceProvider.php

app/Providers/RouteServiceProvider.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Providers;
 
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
 
  
 
class RouteServiceProvider extends ServiceProvider
{
 
    /**
     * 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';
    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')
                ->group(base_path('routes/api.php'));
        });
 
    }
    ....

routes/web.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
use Illuminate\Support\Facades\Route;
 
  
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
 
  
 
Route::get('/', function () {
 
    return view('welcome');
 
});
 
Route::get('student', 'StudentController@index');

Laravel Tags:Laravel 8, laravel 8 example, target class does not exist laravel

Post navigation

Previous Post: Laravel 8 CRUD (Create Read Update Delete) Tutorial For Beginners
Next Post: Laravel 8 CRUD Operation With Ajax Example

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com