sarga/packages/Webkul/Attribute/src/Http/Controllers/AttributeController.php

130 lines
3.0 KiB
PHP
Raw Normal View History

2018-07-11 05:41:27 +00:00
<?php
namespace Webkul\Attribute\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
2018-07-17 13:28:34 +00:00
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
2018-07-11 05:41:27 +00:00
/**
* Catalog attribute controller
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AttributeController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
2018-07-17 13:28:34 +00:00
/**
* AttributeRepository object
*
* @var array
*/
protected $attribute;
2018-07-11 05:41:27 +00:00
/**
* Create a new controller instance.
*
2018-07-17 13:28:34 +00:00
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
2018-07-11 05:41:27 +00:00
* @return void
*/
2018-07-17 13:28:34 +00:00
public function __construct(Attribute $attribute)
2018-07-11 05:41:27 +00:00
{
2018-07-17 13:28:34 +00:00
$this->attribute = $attribute;
2018-07-11 05:41:27 +00:00
$this->_config = request('_config');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view($this->_config['view']);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
2018-07-17 13:28:34 +00:00
return view($this->_config['view']);
2018-07-11 05:41:27 +00:00
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$this->validate(request(), [
2018-08-09 04:35:13 +00:00
'code' => ['required', 'unique:attributes,code', new \Webkul\Core\Contracts\Validations\Code],
2018-07-17 13:28:34 +00:00
'admin_name' => 'required',
2018-07-11 05:41:27 +00:00
'type' => 'required'
]);
2018-07-17 13:28:34 +00:00
$this->attribute->create(request()->all());
2018-07-11 05:41:27 +00:00
session()->flash('success', 'Attribute created successfully.');
return redirect()->route($this->_config['redirect']);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
2018-08-22 09:44:35 +00:00
$attribute = $this->attribute->find($id);
2018-07-11 05:41:27 +00:00
2018-07-17 13:28:34 +00:00
return view($this->_config['view'], compact('attribute'));
2018-07-11 05:41:27 +00:00
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate(request(), [
2018-08-09 04:35:13 +00:00
'code' => ['required', 'unique:attributes,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
2018-07-17 13:28:34 +00:00
'admin_name' => 'required',
'type' => 'required'
2018-07-11 05:41:27 +00:00
]);
2018-07-17 13:28:34 +00:00
$this->attribute->update(request()->all(), $id);
2018-07-11 05:41:27 +00:00
2018-07-17 13:28:34 +00:00
session()->flash('success', 'Attribute updated successfully.');
2018-07-11 05:41:27 +00:00
return redirect()->route($this->_config['redirect']);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}