- Added DTOs (`AssignUsersToRoleData`, `RoleUserData`, `UserSelectData`) for user-role operations and UI data mapping. - Updated `RoleService` and `AppRoleService` with methods for user-role assignment, detachment, retrieval, and search. - Enhanced Blade views and Livewire components to support user-role management in "Roles and Apps." - Adjusted `Role`, `User`, and related models to incorporate Spatie roles and permissions support. - Improved UI with search and selection capabilities for assigning users to roles.
30 lines
573 B
PHP
30 lines
573 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Data\Role;
|
|
|
|
use App\Models\User;
|
|
use Spatie\LaravelData\Data;
|
|
|
|
final class RoleUserData extends Data
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $name,
|
|
public string $initials = '',
|
|
) {}
|
|
|
|
/**
|
|
* Intercept the Eloquent model and map it to the DTO properties.
|
|
*/
|
|
public static function fromModel(User $user): self
|
|
{
|
|
return new self(
|
|
id: $user->id,
|
|
name: $user->name,
|
|
initials: $user->initials()
|
|
);
|
|
}
|
|
}
|