2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Traits\Controllers;
|
|
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
use App\Actions\Common\ToggleModelStatus;
|
|
|
|
|
use App\Actions\Common\ToggleModelStatusInput;
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Contracts\Executor;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Interfaces\ModelWithStatus;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
/**
|
|
|
|
|
* @mixin \Illuminate\Routing\Controller
|
|
|
|
|
*/
|
2026-06-14 21:32:07 +02:00
|
|
|
trait TogglesModelStatus
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Toggles model status
|
|
|
|
|
*/
|
2026-09-29 14:51:46 +02:00
|
|
|
public function toggleStatus(
|
|
|
|
|
Model & ModelWithStatus $model,
|
|
|
|
|
ToggleModelStatus $action,
|
2026-09-29 16:59:07 +02:00
|
|
|
Executor $executor
|
2026-09-29 14:51:46 +02:00
|
|
|
): RedirectResponse {
|
2026-06-14 21:32:07 +02:00
|
|
|
$this->authorize('toggleStatus', $model);
|
|
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
$executor->execute($action, new ToggleModelStatusInput($model));
|
2026-06-14 21:32:07 +02:00
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
return back()->with('success', trans('crud.messages.has_been_updated', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice('models.classes.' . $model->getTable(), 1)),
|
|
|
|
|
]));
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|