ldc-wenn-dann-mit-respekt/app/Traits/Controllers/UpdateModelStatus.php
Noah Lancien 222347d890 phpstan
2024-01-29 16:20:14 +01:00

25 lines
637 B
PHP

<?php
namespace App\Traits\Controllers;
use Illuminate\Database\Eloquent\Model;
/**
* 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 UpdateModelStatus
{
/**
* Change model published
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Http\RedirectResponse
*/
public function changePublished(Model $model)
{
$model->update(['status' => !$model->getOriginal('status')]);
return redirect()->back()->with('success', __('The status has been changed'));
}
}