
Target class [admin] does not exist.
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
Answers 1
-
Create Admin middleware to authenticate admin users
//1. Create middleware to authenticate admin users using php artisan command</span></p> php artisan make:middleware Admin //2. Edit middleware Admin.php //app\Http\Middleware\Admin.php</strong></p> public function handle($request, Closure $next) { if (Auth::check() && Auth::user()->user_type == 'admin') { return $next($request); } else { return redirect('/'); } } //3. <span style="font-weight: 400;">Add it to the routeMiddleware array in your kernel file //app/http/Kernel.php protected $routeMiddleware = [ 'admin' => 'App\Http\Middleware\Admin', ]; //4. <span style="font-weight: 400;">Use Admin middleware to Route group //routes\web.php Route::middleware(['admin'])->group(function () { Route::get('admin/dashboard', '[email protected]')->name('admin.dashboard'); });
0
Random Code Snippet Queries: Laravel
- How to pass variable from controller to model in Laravel
- How to create static page in Laravel
- How to get single column value in laravel
- Laravel get single row by id
- How to Get records between two dates in Laravel
- Call to a member function update() on null
- Submit form without CSRF token in Laravel
- Route prefix with auth middleware in laravel
- Permission denied error while creating storage link in Laravel
- Insert dummy data in users table Laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- Extract only time from datetime in laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Display message with session flash using bootstrap alert class in laravel
- Pagination in laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to get selected categories on edit record with Select2
- Generate unique username in Laravel
- Update existing pivot table data in laravel
- Call to undefined method App\Models\User::follow()
- Recursive function example code PHP Laravel
- Get the post details if it has at least one comment in comments table
- Save or update pivot table data with additional column in Laravel
- How to pass data to multiple partial view files in laravel
- Symlink(): No such file or directory