feature: authorization -add roles column in users
This commit is contained in:
parent
684b7585bb
commit
aef951f71d
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
10
backend/app/Enums/UserRoles.php
Normal file
10
backend/app/Enums/UserRoles.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum UserRoles: string
|
||||
{
|
||||
case Admin = 'admin';
|
||||
case Customer = 'customer';
|
||||
case Broker = 'broker';
|
||||
}
|
||||
@ -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());
|
||||
|
||||
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user