ldc-volena/app/Traits/Controllers/UpdateModelPublished.php

26 lines
696 B
PHP
Raw Permalink Normal View History

2023-11-13 11:56:06 +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 UpdateModelPublished
{
/**
* Change model published.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return \Illuminate\Http\RedirectResponse
*/
2024-03-20 17:39:24 +01:00
public function changePublished(Model $model): \Illuminate\Http\RedirectResponse
2023-11-13 11:56:06 +01:00
{
$model->update(['published' => !$model->getOriginal('published')]);
2023-11-13 11:56:06 +01:00
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
}
}