0
votes

before uploading to cpanel i tried my laravel project and all work well. after i uploading it to cpanel all page that don't have middeware work well but the page with middleware return:

ReflectionException (-1)Class App\Http\Middleware\MyMiddleware does not exist

here my middeware at App\Http\Middleware\MyMiddleware.php

namespace App\Http\Middleware;

use Closure;

class MyMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(session()->has('adminId')){
            return redirect('/admin/dashboard');
        }else{
            if($request->path() == 'admin'){
                return redirect('/admin/login');
            }else{
                return $next($request);
            }
        }
    }
}

and here is my App\Http\Kernel.php

protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'myAuth' => \App\Http\Middleware\MyMiddleware::class,
];

here is my route at routes/web.php

Route::get('/admin', ['middleware' => 'myAuth', 'uses' => function(){
echo "nothing";}]);

so far i have try

php artisan config:clear
composer update
composer dump-autoload

before uploading to cpanel, but no luck.

2
Please read this This Question may it'll help you.Jaydeep Mor
ok reading and trying right now.Wilz_li
and no luck still giving the same errorWilz_li

2 Answers

0
votes

I think your file name lacks a 'l' in MyMidd'l'eware.

Do composer dump autoload and then rename your file name.

Your file name and your class name must be same i guess.

-1
votes

For me it was 2 issues - I was using the middleware as route middleware so in

monitoring_api_6/app/Http/Kernel.php

It was necessary to add

nodeVerification' => \App\Http\Middleware\NodeVerification::class

to the $routeMiddleware array.

my 2nd issue was that I'd capitalised the n in nodeVerification when using the middleware on the route.