2023-03-16 15:08:37 +01:00
|
|
|
<?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->status = !$model->status;
|
|
|
|
|
$model->saveOrFail();
|
2023-03-23 09:08:28 +01:00
|
|
|
|
|
|
|
|
if (!$model->saveOrFail()) {
|
|
|
|
|
return redirect()->back()->with('error', __('The status could not be changed'));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->back()->with('success', __('The status has been changed'));
|
2023-03-16 15:08:37 +01:00
|
|
|
}
|
|
|
|
|
}
|