Target Class Does Not Exist in Laravel 8

Target Class Does Not Exist in Laravel 8

If you need to see an example of target class does not exist in laravel 8. you will learn Target class class no laravel 8. step by step explain target class no exist in laravel 8. I will show you with target class not found in laravel.

Just yesterday laravel 8 was launched and I was trying to create my first system with laravel 8 and when I made the controller call UserController and when I used the track I found the following problem:

Read Also :  How to Solve 419 Page Expired Laravel

Target category [UserController] does not exist

you can see the bellow screenshot too.

Actually this is not a mistake but laravel 8 has removed the RouteServiceProvider.php space name form. but i will mention this nice feature if you want to call your control section from a different name area.

but now if you want to find a solution I will give you two solutions. you can use it in the route file or you can specify the default namespace in the RouteServiceProvider.php file. let’s see both solutions one by one.

Read Also :  Laravel Blade If Multiple Conditions Example

Step for Target Class Does Not Exist in Laravel 8

Step :1 routes/web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get("welcome",[UserController::class,'user']);

Step : 2 UserController.php

<?php
  namespace App\Http\Controllers;
  class UserController extends Controller {

  function user(){
    return view("welcome");
  }
}

Step : 3 welcome.blade.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Laravel Flash Message Tutorial</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>

<body>

 <div class="container">

   <div>
     <h1>Laravel Flash Messages</h1>
   </div>
</div>
</body>
</html>

I hope it can help you…