`Admin.php` [Middlewere]

```php
public function handle($request, Closure $next)
{
   if (Auth::check() && Auth::user()->role->name == 'admin') {
      return $next($request);
   }
   return Redirect::route('home');
}

```

> 
> I want to check if the column **`name`** of `roles` table is equal to `admin`.
> 
> 
> 

> 
> I have tried with `Auth::user()->role->name == 'admin')`.
> 
> 
> 

**Error I am getting**

> 
> Property [name] does not exist on this collection instance.
> 
> 
> 

**Reference Model**

`User.php` [Model]

```php
public function role()
{
   return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id')->withTimestamps();
}

```

**Reference table**

`users` table

```php
         Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->string('photo')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->longText('cartitems')->nullable();
            $table->longText('wishlist')->nullable();
            $table->unsignedBigInteger('discount')->default(0);
            $table->rememberToken();
            $table->timestamps();
        });

```

> 
> This is `users` table. **Notice** there is no role directly here.
> 
> 
> 

`roles` table

```php
       Schema::create('roles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('display_name');
            $table->timestamps();
        });

```

> 
> This is `roles` table. And every user have a role such as `Superadmin`, `admin`, `seller` or`customer`
> 
> 
> 

`role_user` table

```php
        Schema::create('role_user', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

            $table->unsignedBigInteger('role_id');
            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');

            $table->timestamps();
        });

```

> 
> In this pivot table make a relationship between `users` and `roles` table.
> 
> 
>