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 $email,
|
||||||
public string $mobileNumber,
|
public string $mobileNumber,
|
||||||
public string $city,
|
public string $city,
|
||||||
|
public string $role
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +26,7 @@ public function toArray(): array
|
|||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'mobileNumber' => $this->mobileNumber,
|
'mobileNumber' => $this->mobileNumber,
|
||||||
'city' => $this->city,
|
'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,
|
name: $user->name,
|
||||||
email: $user->email,
|
email: $user->email,
|
||||||
mobileNumber: $user->mobile_number,
|
mobileNumber: $user->mobile_number,
|
||||||
city: $user->city
|
city: $user->city,
|
||||||
|
role: $user->role->value
|
||||||
);
|
);
|
||||||
|
|
||||||
return response()->json($userDto->toArray());
|
return response()->json($userDto->toArray());
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
use App\Enums\UserRoles;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
@ -23,6 +24,7 @@ class User extends Authenticatable
|
|||||||
'password',
|
'password',
|
||||||
'city',
|
'city',
|
||||||
'mobile_number',
|
'mobile_number',
|
||||||
|
'role',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +47,7 @@ protected function casts(): array
|
|||||||
return [
|
return [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
'password' => 'hashed',
|
'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