ldc-legaulois/app/Traits/Controllers/UpdateModelPublished.php

25 lines
602 B
PHP
Raw Permalink Normal View History

2024-01-10 14:49:46 +01:00
<?php
namespace App\Traits\Controllers;
use Illuminate\Database\Eloquent\Model;
2026-09-25 16:25:31 +02:00
use Illuminate\Http\RedirectResponse;
2024-01-10 14:49:46 +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-25 16:25:31 +02:00
public function changePublished(Model $model): RedirectResponse
2024-01-10 14:49:46 +01:00
{
2026-09-25 16:25:31 +02:00
$model->update(['published' => ! $model->getOriginal('published')]);
return redirect()->back()->with('success', trans('crud.messages.publish_status_saved'));
2024-01-10 14:49:46 +01:00
}
}