0

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.

Wilz_li
  • 1
  • 1
  • 3

1 Answers1

0

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.

prit.patel
  • 330
  • 3
  • 12
  • ahh..sorry it was a typo when i type a question. i edited it thanks. got any idea what's wrong with my code? as i mention that i already try it in local and all works fine. but it's get that error after i uploading it to cpanel – Wilz_li May 31 '18 at 04:51