- Added `app_roles` migration to manage role assignments for connected apps, supporting role duration and indexing. - Introduced `AppRole` pivot model for managing `ConnectedApp` and `Role` relationships. - Updated `ConnectedApp` and `Role` models with `BelongsToMany` relationships for role associations. - Adjusted `permission` config to use custom `Role` model.
40 lines
830 B
PHP
40 lines
830 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\{Relations\BelongsTo, Relations\Pivot};
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $app_id
|
|
* @property int $role_id
|
|
* @property int $duration Duration in days.
|
|
*/
|
|
#[Fillable(['app_id', 'role_id', 'duration'])]
|
|
class AppRole extends Pivot
|
|
{
|
|
public $timestamps = false;
|
|
|
|
protected $table = 'app_roles';
|
|
|
|
/**
|
|
* @return BelongsTo<ConnectedApp, $this>
|
|
*/
|
|
public function app(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ConnectedApp::class, 'app_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Role, $this>
|
|
*/
|
|
public function role(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Role::class, 'role_id');
|
|
}
|
|
}
|