ldc-le-gaulois-pro/app/Traits/Controllers/UpdateModelPublished.php

26 lines
661 B
PHP
Raw Normal View History

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