vito/app/Actions/SshKey/CreateSshKey.php
2025-03-12 13:31:10 +01:00

43 lines
846 B
PHP

<?php
namespace App\Actions\SshKey;
use App\Models\SshKey;
use App\Models\User;
use App\ValidationRules\SshKeyRule;
use Illuminate\Validation\ValidationException;
class CreateSshKey
{
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function create(User $user, array $input): SshKey
{
$key = new SshKey([
'user_id' => $user->id,
'name' => $input['name'],
'public_key' => $input['public_key'],
]);
$key->save();
return $key;
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'name' => 'required',
'public_key' => [
'required',
new SshKeyRule,
],
];
}
}