2026-09-29 14:51:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
namespace App\Cqs\Actions\Common;
|
2026-09-29 14:51:46 +02:00
|
|
|
|
|
|
|
|
use App\Contracts\Action;
|
|
|
|
|
use App\Contracts\ActionInput;
|
|
|
|
|
use App\Interfaces\ModelWithStatus;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-10 18:17:04 +01:00
|
|
|
* @implements \App\Contracts\Action<
|
|
|
|
|
* \App\Cqs\Actions\Common\ToggleModelStatusInput,
|
|
|
|
|
* \Illuminate\Database\Eloquent\Model&\App\Interfaces\ModelWithStatus
|
|
|
|
|
* >
|
2026-09-29 14:51:46 +02:00
|
|
|
*/
|
|
|
|
|
final class ToggleModelStatus implements Action
|
|
|
|
|
{
|
|
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @param \App\Cqs\Actions\Common\ToggleModelStatusInput $input
|
2026-09-29 14:51:46 +02:00
|
|
|
*/
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function __invoke(ActionInput $input): Model & ModelWithStatus
|
|
|
|
|
{
|
|
|
|
|
Assert::isInstanceOf($input, ToggleModelStatusInput::class);
|
|
|
|
|
|
|
|
|
|
$model = $input->model;
|
|
|
|
|
$model->toggleStatus();
|
|
|
|
|
$model->saveOrFail();
|
|
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
}
|