ldc-loue/app/Traits/Controllers/UpdateModelStatus.php

27 lines
587 B
PHP
Raw Normal View History

2022-06-01 13:41:24 +02:00
<?php
2022-07-04 10:17:34 +00:00
namespace App\Traits\Controllers;
2022-06-01 13:41:24 +02:00
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
*
2022-07-18 08:24:42 +00:00
* @param \Illuminate\Database\Eloquent\Model $model
2022-06-01 13:41:24 +02:00
* @return \Illuminate\Http\RedirectResponse
*/
public function changePublished(Model $model)
{
$model->status = !$model->status;
$model->saveOrFail();
return redirect()->back();
}
}