2023-11-23 17:31:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-09-18 15:57:56 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2023-11-23 17:31:28 +01:00
|
|
|
namespace App\Traits\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-09-18 15:57:56 +02:00
|
|
|
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.
|
|
|
|
|
*/
|
2026-09-18 15:57:56 +02:00
|
|
|
public function changePublished(Model $model): RedirectResponse
|
2023-11-23 17:31:28 +01:00
|
|
|
{
|
2026-09-18 15:57:56 +02:00
|
|
|
$model->update(['published' => ! $model->getOriginal('published')]);
|
|
|
|
|
|
2023-11-23 17:31:28 +01:00
|
|
|
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
|
|
|
|
|
}
|
|
|
|
|
}
|