63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\View\Components\Private\Forms;
|
|
|
|
use App\Enums\Permission;
|
|
use App\Models\Role;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\View\View;
|
|
|
|
final class PermissionsForRole extends Form
|
|
{
|
|
public function __construct(
|
|
private readonly string $title,
|
|
private readonly string $name,
|
|
private readonly Role $role,
|
|
private readonly array $value
|
|
) { }
|
|
|
|
protected function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function getTitle(): string
|
|
{
|
|
return Str::ucfirst($this->title);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
private function getValue(): Collection
|
|
{
|
|
$value = old($this->getRequestName(), $this->value);
|
|
return collect($value);
|
|
}
|
|
|
|
/**
|
|
* @return Role
|
|
*/
|
|
private function getRole(): Role
|
|
{
|
|
return $this->role;
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('private.components.forms.permissions_for_role', [
|
|
'title' => $this->getTitle(),
|
|
'name' => $this->getName(),
|
|
'requestName' => $this->getRequestName(),
|
|
'permissions' => Permission::cases(),
|
|
'role' => $this->getRole(),
|
|
'value' => $this->getValue(),
|
|
]);
|
|
}
|
|
|
|
}
|