ldc-loue/app/Traits/UpdateModelStatus.php
2022-06-01 14:29:31 +02:00

26 lines
545 B
PHP

<?php
namespace App\Traits;
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 Model $model
* @return \Illuminate\Http\RedirectResponse
*/
public function changePublished(Model $model)
{
$model->status = !$model->status;
$model->saveOrFail();
return redirect()->back();
}
}