
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
- Redirect to previous page or url in laravel
- How to change default timestamp fields name in Laravel
- Include External CSS and JS file in Laravel
- How to generate .env file for laravel?
- Get current month records in laravel 7/8
- Return view from route Laravel
- Attempt to read property "avatar" on null in Laravel
- Laravel get all records with pagination
- How to get single column value in laravel
- Extract only time from datetime in laravel
- Convert multidimensional array to single array in Laravel
- Permission denied error while creating storage link in Laravel
- Get last year created records in Laravel
- Database transactions in laravel
- Laravel upload file with original file name
- How to add a key value pair to existing array in laravel
- How to check data inserted or deleted in pivot after toggle method
- How to automatically update the timestamp of parent model in Laravel
- How to upload image in laravel 8
- How to create event and listener in laravel ?
- How to Get records between two dates in Laravel
- How to update record after save method in Laravel
- Create project table with model and migration
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Use of undefined constant laravel