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
- Use of undefined constant laravel
- How to call Laravel route in jQuery
- Call to a member function pluck() on array
- How to check duplicate entry in laravel
- How to use or operator in laravel
- If condition in Laravel 9
- Redirect to another view from controller in laravel
- Laravel change date format
- Generate unique username in Laravel
- How to display pivot table column value in laravel
- Calculate age from date of birth in Laravel
- Array to string conversion laravel blade
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Property [user] does not exist on this collection instance
- Delete records with relationship in laravel
- Rename Pivot Table in Laravel
- How to add class to tr in table using foreach in laravel
- Laravel append URI in route
- Trying to get property 'title' of non-object
- Laravel clone model
- How to call controller function from view in Laravel
- Where to use whereNotNull eloquent in laravel
- Insert Comma Separated Values in laravel
- After image selected get validation error in laravel
- Laravel create multiple records in Pivot table