You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/app/Http/Controllers/Admin/SliderController.php

129 lines
3.5 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\SliderSaveRequest;
use App\Models\Access;
use App\Models\Slider;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class SliderController extends XController
{
// protected $_MODEL_ = Slider::class;
// protected $SAVE_REQUEST = SliderSaveRequest::class;
protected $cols = ['body','status'];
protected $extra_cols = ['id','image'];
protected $searchable = ['body'];
protected $listView = 'admin.sliders.slider-list';
protected $formView = 'admin.sliders.slider-form';
protected $buttons = [
'edit' =>
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
'show' =>
['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
'destroy' =>
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];
public function __construct()
{
parent::__construct(Slider::class, SliderSaveRequest::class);
}
/**
* @param $slider Slider
* @param $request SliderSaveRequest
* @return Slider
*/
public function save($slider, $request)
{
$slider->body = $request->input('body', '');
$slider->status = $request->input('status');
$slider->data = $request->input('data');
$slider->user_id = auth()->id();
if ($request->hasFile('cover')) {
$name = time() . '.' . request()->cover->getClientOriginalExtension();
$slider->image = $name;
$request->file('cover')->storeAs('public/sliders', $name);
}
if ($request->has('cover')){
$slider->image = $this->storeFile('cover',$slider, 'sliders');
}
$slider->save();
return $slider;
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Slider $item)
{
//
return view($this->formView, compact('item'));
}
public function bulk(Request $request)
{
// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;
case 'publish':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]);
$msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]);
break;
case 'draft':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]);
$msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]);
break;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Slider $item)
{
return parent::delete($item);
}
public function update(Request $request, Slider $item)
{
return $this->bringUp($request, $item);
}
}