ldc-gen-game-web/app/Traits/Controllers/UpdateModelPublished.php

27 lines
620 B
PHP
Raw Permalink Normal View History

2023-11-23 17:31:28 +01:00
<?php
declare(strict_types=1);
2023-11-23 17:31:28 +01:00
namespace App\Traits\Controllers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\RedirectResponse;
2023-11-23 17:31:28 +01:00
/**
* This trait works with Route::bind in App service provider
* to resolve the model and the DB row
* It does not work with binder Service
*/
trait UpdateModelPublished
{
/**
* Change model published.
*/
public function changePublished(Model $model): RedirectResponse
2023-11-23 17:31:28 +01:00
{
$model->update(['published' => ! $model->getOriginal('published')]);
2026-10-02 12:09:46 +02:00
return back()->with('success', trans(__('crud.messages.publish_status_saved')));
2023-11-23 17:31:28 +01:00
}
}