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

26 lines
658 B
PHP
Raw Permalink Normal View History

2023-02-24 15:20:58 +00: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
{
/**
2024-09-06 08:30:55 +00:00
* Change model published.
2023-02-24 15:20:58 +00:00
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Http\RedirectResponse
*/
public function changePublished(Model $model)
{
2024-09-06 08:30:55 +00:00
$model->update(['published' => !$model->getOriginal('published')]);
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
2023-02-24 15:20:58 +00:00
}
}