2018-08-03 14:50:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Shop\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Routing\Controller;
|
|
|
|
|
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 11:00:15 +00:00
|
|
|
$this->slider->save(request()->all());
|
2018-10-17 10:33:57 +00:00
|
|
|
|
2018-08-09 12:00:26 +00:00
|
|
|
session()->flash('success', 'Slider created successfully.');
|
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 11:00:15 +00:00
|
|
|
$result = $this->slider->updateItem(request()->all(), $id);
|
|
|
|
|
|
|
|
|
|
if($result) {
|
2018-10-17 10:33:57 +00:00
|
|
|
session()->flash('success', 'Slider Item Successfully Updated');
|
|
|
|
|
} else {
|
|
|
|
|
session()->flash('error', 'Slider Cannot Be Updated');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) {
|
|
|
|
|
session()->flash('warning', 'Cannot Delete The Last Slider Item');
|
|
|
|
|
} else {
|
|
|
|
|
$this->slider->destroy($id);
|
|
|
|
|
|
|
|
|
|
session()->flash('success', 'Slider Item Successfully Deleted');
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 13:47:40 +00:00
|
|
|
return redirect()->back();
|
2018-08-03 14:50:13 +00:00
|
|
|
}
|
|
|
|
|
}
|