Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateModelPublished
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 changePublished
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Traits\Controllers;
4
5use Illuminate\Database\Eloquent\Model;
6
7/**
8 * This trait works with Route::bind in App service provider
9 * to resolve the model and the DB row
10 * It does not work with binder Service
11 */
12trait UpdateModelPublished
13{
14    /**
15     * Change model published.
16     *
17     * @param \Illuminate\Database\Eloquent\Model $model
18     * @return \Illuminate\Http\RedirectResponse
19     */
20    public function changePublished(Model $model)
21    {
22        $model->published = !$model->published;
23        $model->saveOrFail();
24        return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
25    }
26}