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\ToggleModelStar;
|
|
|
|
|
use App\Actions\Common\ToggleModelStarInput;
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Contracts\Executor;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Interfaces\ModelWithStar;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @mixin \Illuminate\Routing\Controller
|
|
|
|
|
*/
|
|
|
|
|
trait TogglesModelStar
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Toggles model star
|
|
|
|
|
*/
|
2026-09-29 14:51:46 +02:00
|
|
|
public function toggleStar(
|
|
|
|
|
Model & ModelWithStar $model,
|
|
|
|
|
ToggleModelStar $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('toggleStar', $model);
|
|
|
|
|
|
2026-09-29 14:51:46 +02:00
|
|
|
$executor->execute($action, new ToggleModelStarInput($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
|
|
|
}
|
|
|
|
|
}
|