130 lines
3.0 KiB
PHP
130 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Webkul\Attribute\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
|
|
|
|
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* AttributeRepository object
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attribute;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @param Webkul\Attribute\Repositories\AttributeRepository $attribute
|
|
* @return void
|
|
*/
|
|
public function __construct(Attribute $attribute)
|
|
{
|
|
$this->attribute = $attribute;
|
|
|
|
$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()
|
|
{
|
|
return view($this->_config['view']);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store()
|
|
{
|
|
$this->validate(request(), [
|
|
'code' => ['required', 'unique:attributes,code', new \Webkul\Core\Contracts\Validations\Code],
|
|
'admin_name' => 'required',
|
|
'type' => 'required'
|
|
]);
|
|
|
|
$this->attribute->create(request()->all());
|
|
|
|
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)
|
|
{
|
|
$attribute = $this->attribute->find($id);
|
|
|
|
return view($this->_config['view'], compact('attribute'));
|
|
}
|
|
|
|
/**
|
|
* 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(), [
|
|
'code' => ['required', 'unique:attributes,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
|
'admin_name' => 'required',
|
|
'type' => 'required'
|
|
]);
|
|
|
|
$this->attribute->update(request()->all(), $id);
|
|
|
|
session()->flash('success', 'Attribute updated successfully.');
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
} |