44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Actions\Ranges;
|
||
|
|
|
||
|
|
use App\Contracts\Action;
|
||
|
|
use App\Contracts\ActionInput;
|
||
|
|
use App\Models\Range;
|
||
|
|
use Webmozart\Assert\Assert;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @implements \App\Contracts\Action<\App\Actions\Ranges\CreateRangeInput, \App\Models\Range>
|
||
|
|
*/
|
||
|
|
final class CreateRange implements Action
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param \App\Actions\Ranges\CreateRangeInput $input
|
||
|
|
*/
|
||
|
|
#[\Override]
|
||
|
|
public function __invoke(ActionInput $input): Range
|
||
|
|
{
|
||
|
|
Assert::isInstanceOf($input, CreateRangeInput::class);
|
||
|
|
|
||
|
|
$attributes = [
|
||
|
|
'name' => $input->name,
|
||
|
|
'description' => $input->description,
|
||
|
|
'picture_alt' => $input->pictureMetadata->alt ?? '',
|
||
|
|
'picture_title' => $input->pictureMetadata->title ?? '',
|
||
|
|
'status' => $input->status,
|
||
|
|
];
|
||
|
|
|
||
|
|
if ($input->picture !== null) {
|
||
|
|
$attributes['picture'] = $input->picture;
|
||
|
|
}
|
||
|
|
|
||
|
|
$range = new Range();
|
||
|
|
$range->fill($attributes);
|
||
|
|
$range->saveOrFail();
|
||
|
|
|
||
|
|
return $range;
|
||
|
|
}
|
||
|
|
}
|