-1

I have recently moved to Laravel from the normal php and I have managed to finish a project in my localhost, everything works fine at least to my expectation but when I moved my files to the server, I am experincing a middleware issue.

Now I have a middleware called isAdmin which was created using the artisan command. I have also registerd the class in the kernel as:

'isAdmin' => \App\Http\Middleware\IsAdmin::class, 

My isAdmin middleware cass is configued as:

<?php

namespace App\Http\Middleware;

use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class isAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {

        if (Auth::user() &&  Auth::user()->isAdmin == 1) {
            return $next($request);
        }

        return redirect('/');
    }
}

this middleware works fine on my localhost, I already grouped all routes using the middleware like so:

Route::group(['middleware' => 'isAdmin'], function () {
        //routes that uses this middlewares here
});

When I uploaded my code to a shared hosting server, I get error:

Target class [App\Http\Middleware\IsAdmin] does not exist.

Can anyone suggest how I can fix this?? I also realize that I can not run artisan command because the current php version on the server is less that 8.0.2

1 Answers1

0

Solution

use App\Http\Middleware\IsAdmin;

Route::group(['middleware' => IsAdmin::class], function () {
    //routes that uses this middlewares here
});
Joukhar
  • 724
  • 1
  • 3
  • 18
  • 1
    aparently I created a middleware isAdmin and I'm calling it as IsAdmin. Your solution made me look at the spelling again. Thank you. Any Idea why it's working on localhost even with this error? – DigitalBraine Aug 19 '22 at 22:52
  • i faced the same error as you in the shared hosting but , idk why . – Joukhar Aug 20 '22 at 01:26