2018-08-03 14:50:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Shop\Http\Controllers;
|
|
|
|
|
|
2018-10-28 13:23:20 +00:00
|
|
|
use Webkul\Shop\Http\Controllers\Controller;
|
|
|
|
|
|
2018-08-03 14:50:13 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Webkul\Core\Repositories\SliderRepository as Slider;
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-10 09:28:35 +00:00
|
|
|
* Slider controller for managing the slider controls.
|
2018-08-03 14:50:13 +00:00
|
|
|
*
|
2018-10-26 07:28:38 +00:00
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
2018-08-03 14:50:13 +00:00
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class SliderController extends controller
|
|
|
|
|
{
|
|
|
|
|
protected $_config;
|
2018-08-08 13:47:40 +00:00
|
|
|
protected $slider;
|
|
|
|
|
protected $channels;
|
2018-08-03 14:50:13 +00:00
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
public function __construct(Slider $slider)
|
2018-08-03 14:50:13 +00:00
|
|
|
{
|
2018-08-08 13:47:40 +00:00
|
|
|
$this->slider = $slider;
|
2018-08-03 14:50:13 +00:00
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
/**
|
2018-10-26 07:28:38 +00:00
|
|
|
* Loads the index for the sliders settings.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
2018-08-08 13:47:40 +00:00
|
|
|
*/
|
|
|
|
|
public function index() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
2018-10-26 07:28:38 +00:00
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
/**
|
2018-10-26 07:28:38 +00:00
|
|
|
* Loads the form for creating slider.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
2018-08-08 13:47:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function create() {
|
2018-08-21 10:58:55 +00:00
|
|
|
$channels = core()->getAllChannels();
|
|
|
|
|
|
2018-10-17 14:20:25 +00:00
|
|
|
return view($this->_config['view']);
|
2018-08-03 14:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
/**
|
2018-10-17 10:33:57 +00:00
|
|
|
* Creates the new sider item.
|
|
|
|
|
*
|
|
|
|
|
* @return response
|
2018-08-08 13:47:40 +00:00
|
|
|
*/
|
|
|
|
|
public function store() {
|
2018-10-28 13:23:20 +00:00
|
|
|
$this->validate(request(), [
|
|
|
|
|
'title' => 'string|required',
|
|
|
|
|
'channel_id' => 'required',
|
2018-12-21 08:35:52 +00:00
|
|
|
'image' => 'required|mimes:jpeg,bmp,png'
|
2018-10-28 13:23:20 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$result = $this->slider->save(request()->all());
|
2018-10-17 10:33:57 +00:00
|
|
|
|
2018-10-28 13:23:20 +00:00
|
|
|
if($result)
|
|
|
|
|
session()->flash('success', trans('admin::app.settings.sliders.created-success'));
|
|
|
|
|
else
|
|
|
|
|
session()->flash('success', trans('admin::app.settings.sliders.created-fail'));
|
2018-10-17 10:33:57 +00:00
|
|
|
|
2018-10-28 11:00:15 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-10-17 10:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Edit the previously created slider item.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id) {
|
|
|
|
|
$slider = $this->slider->find($id);
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'])->with('slider', $slider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Edit the previously created slider item.
|
|
|
|
|
*
|
|
|
|
|
* @return response
|
|
|
|
|
*/
|
|
|
|
|
public function update($id) {
|
2018-10-28 13:23:20 +00:00
|
|
|
$this->validate(request(), [
|
|
|
|
|
'title' => 'string|required',
|
|
|
|
|
'channel_id' => 'required',
|
2018-12-21 08:35:52 +00:00
|
|
|
'image' => 'sometimes|mimes:jpeg,bmp,png'
|
2018-10-28 13:23:20 +00:00
|
|
|
]);
|
|
|
|
|
|
2018-10-28 11:00:15 +00:00
|
|
|
$result = $this->slider->updateItem(request()->all(), $id);
|
|
|
|
|
|
|
|
|
|
if($result) {
|
2018-10-28 13:23:20 +00:00
|
|
|
session()->flash('success', trans('admin::app.settings.sliders.update-success'));
|
2018-10-17 10:33:57 +00:00
|
|
|
} else {
|
2018-10-28 13:23:20 +00:00
|
|
|
session()->flash('error', trans('admin::app.settings.sliders.update-fail'));
|
2018-10-17 10:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-28 13:23:20 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-10-17 10:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a slider item and preserve the last one from deleting
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id) {
|
|
|
|
|
if($this->slider->findWhere(['channel_id' => core()->getCurrentChannel()->id])->count() == 1) {
|
2018-10-28 13:23:20 +00:00
|
|
|
session()->flash('warning', trans('admin::app.settings.sliders.delete-success'));
|
2018-10-17 10:33:57 +00:00
|
|
|
} else {
|
|
|
|
|
$this->slider->destroy($id);
|
|
|
|
|
|
2018-10-28 13:23:20 +00:00
|
|
|
session()->flash('success', trans('admin::app.settings.sliders.delete-fail'));
|
2018-10-17 10:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
return redirect()->back();
|
2018-08-03 14:50:13 +00:00
|
|
|
}
|
|
|
|
|
}
|