mardi 1 juin 2021

Error: Call to undefined method App\User::admin()

Im getting this error Call to undefined method App\User::admin() it's working fine when I'm in guest mode. But when Im in admin mode I always gets an error whenever I go to other routes. here is my controller

this is my route

Route::get('/users','UserController@index')->middleware(IsAdmin::class);

this is my controller public function index()

  {
        $users = User::all();
        return view('posts.showusers')->with('users',$users);
    }

this is my Middleware

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class IsAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        {
            if ( Auth::check() && Auth::user()->admin() )
            {
                return $next($request);
            }
    
            return redirect('home');
        }
    }
}

How can I fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire