
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', '[email protected]')->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
- How to Access Array in blade laravel
- How to create belongstomany relation using custom name on custom pivot table
- Class 'App\Rules\Hash' not found in Laravel
- Redirect from www to non www in laravel using htaccess
- Always load the relationship data with eager loading in Laravel
- How to get column names from table in Laravel
- Laravel route redirect not working
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Rename Pivot Table in Laravel
- How to remove P tag from CkEditor in Laravel?
- Ignore Records where a field has NULL value in Laravel
- Get last week data in Laravel
- Ajax GET request in laravel
- How to get data from two tables in laravel
- Retain selected value of select box in Laravel
- How to insert dynamic value to additional column in pivot table in laravel
- Create record with unique slug in laravel
- How to get random string in Laravel
- Permanently delete a record in laravel
- Link storage folder in laravel 8
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Symlink(): No such file or directory
- Insert values in pivot table dynamically in laravel
- How to pass query string with pagination in laravel