Target class [admin] does not exist.
Target class [admin] does not exist.
Hello everyone, in this post we will examine how to solve the "Target class [admin] does not exist." programming puzzle.
I got error Target class [admin] does not exist while using admin middleware to authenticate admin users because I did not use the admin middleware 'admin' => 'App\Http\Middleware\Admin', in app\Http\Kernel.php file. Hope it will help you to find the solution for you-
Create Admin middleware to authenticate admin users
- Create middleware to authenticate admin users using php artisan command
php artisan make:middleware Admin
- Edit middleware Admin.php
app\Http\Middleware\Admin.php
public function handle($request, Closure $next) { if (Auth::check() && Auth::user()->user_type == 'admin') { return $next($request); } else { return redirect('/'); } }
- Add it to the routeMiddleware array in your kernel file
app/http/Kernel.php
protected $routeMiddleware = [ 'admin' => 'App\Http\Middleware\Admin', ];
- Use Admin middleware to Route group
routes\web.php
Route::middleware(['admin'])->group(function () { Route::get('admin/dashboard', 'AdminController@Index')->name('admin.dashboard'); });
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Ajax GET request in laravel
- Get previous date data in laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- Create record with unique slug in laravel
- How to get tomorrow and yesterday date in laravel
- How to get all route list
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to fetch single row data from database in laravel
- Run artisan command to generate key in laravel
- The use statement with non-compound name 'DB' has no effect
- Laravel 5.4 save data to database
- Class 'App\Rules\Hash' not found in Laravel
- Calculate age from date of birth in Laravel
- Laravel get count with where condition
- Automatically remove records using Prunable trait in Laravel
- Link storage folder in laravel 8
- Redirect from www to non www in laravel using htaccess
- Laravel create table migration with model
- How to decrypt laravel password
- Php artisan make model, factory, migration and controller in single command
- Method chaining in Laravel
- How to get path from current URL in Laravel
- Datetime field in Laravel migration
- Update if exist else insert new record in laravel
- Laravel 11 sanctum api authentication example code