Laravel 5.3 Middleware class does not exist

I would like to do some middleware authentication .. But unfortunately, it is returning as the class does not exist

Here is my middleware

Staff.php

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class Staff
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = Auth::user()->type;
        if ($user == 'S'){
            return $next($request);
        }

        return "no";
    }
}

Here is the core .php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    protected $middleware = [
        \App\http\Middleware\Staff::class,
    ];

    /**
     * Define the application command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

I tried dump-autoload linker but it is not efficient.

Here is my route:

Route::get('/staff', 'StaffController@index')->middleware('Staff');
+4
source share
1 answer

If you want to apply middlewares to Http calls, you must register them with app/Http/Kernel.php. However, your middleware is registered for console commands at App\Console\Kernel. See more on the Laravel documentation

+10
source

Source: https://habr.com/ru/post/1653505/


All Articles