feature: authorization -add roles column in users

This commit is contained in:
kusowl 2026-02-27 13:20:55 +05:30
parent 684b7585bb
commit aef951f71d
5 changed files with 40 additions and 1 deletions

View File

@ -12,6 +12,7 @@ public function __construct(
public string $email,
public string $mobileNumber,
public string $city,
public string $role
) {}
/**
@ -25,6 +26,7 @@ public function toArray(): array
'email' => $this->email,
'mobileNumber' => $this->mobileNumber,
'city' => $this->city,
'role' => $this->role,
];
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Enums;
enum UserRoles: string
{
case Admin = 'admin';
case Customer = 'customer';
case Broker = 'broker';
}

View File

@ -40,7 +40,8 @@ public function show()
name: $user->name,
email: $user->email,
mobileNumber: $user->mobile_number,
city: $user->city
city: $user->city,
role: $user->role->value
);
return response()->json($userDto->toArray());

View File

@ -3,6 +3,7 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\UserRoles;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -23,6 +24,7 @@ class User extends Authenticatable
'password',
'city',
'mobile_number',
'role',
];
/**
@ -45,6 +47,7 @@ protected function casts(): array
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'role' => UserRoles::class,
];
}
}

View File

@ -0,0 +1,23 @@
<?php
use App\Enums\UserRoles;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->enum('role', array_column(UserRoles::cases(), 'value'))->default(UserRoles::Customer->value);
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('role');
});
}
};