2018-07-02 09:29:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\User\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-07-31 07:50:54 +00:00
|
|
|
use Webkul\User\Repositories\RoleRepository as Role;
|
2018-07-02 09:29:27 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Admin user role controller
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class RoleController extends Controller
|
|
|
|
|
{
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2018-07-02 09:29:27 +00:00
|
|
|
protected $_config;
|
2018-08-31 06:03:11 +00:00
|
|
|
|
2018-07-31 07:50:54 +00:00
|
|
|
/**
|
|
|
|
|
* RoleRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $role;
|
2018-07-02 09:29:27 +00:00
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
2018-07-31 07:50:54 +00:00
|
|
|
* @param Webkul\User\Repositories\RoleRepository $role
|
2018-07-05 07:58:26 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-07-31 07:50:54 +00:00
|
|
|
public function __construct(Role $role)
|
2018-07-02 09:29:27 +00:00
|
|
|
{
|
2018-08-31 06:03:11 +00:00
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
2018-07-31 07:50:54 +00:00
|
|
|
$this->role = $role;
|
|
|
|
|
|
2018-07-02 09:29: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()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view'], compact('roleItems'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store(Request $request)
|
|
|
|
|
{
|
2018-07-05 07:58:26 +00:00
|
|
|
$this->validate(request(), [
|
|
|
|
|
'name' => 'required',
|
|
|
|
|
'permission_type' => 'required',
|
|
|
|
|
]);
|
|
|
|
|
|
2018-07-31 07:50:54 +00:00
|
|
|
$this->role->create(request()->all());
|
2018-07-02 09:29:27 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', 'Role 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
|
|
|
$role = $this->role->find($id);
|
2018-07-02 09:29:27 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('role'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
2018-07-11 05:41:27 +00:00
|
|
|
$this->validate(request(), [
|
|
|
|
|
'name' => 'required',
|
|
|
|
|
'permission_type' => 'required',
|
|
|
|
|
]);
|
2018-08-31 06:03:11 +00:00
|
|
|
|
2018-07-31 07:50:54 +00:00
|
|
|
$this->role->update(request()->all(), $id);
|
2018-07-02 09:29:27 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', 'Role 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)
|
|
|
|
|
{
|
2018-10-17 07:21:47 +00:00
|
|
|
if($this->role->count() == 1) {
|
|
|
|
|
session()->flash('error', 'At least one role is required.');
|
|
|
|
|
} else {
|
|
|
|
|
$this->role->delete($id);
|
|
|
|
|
|
|
|
|
|
session()->flash('success', 'Role source deleted successfully.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
2018-07-02 09:29:27 +00:00
|
|
|
}
|
|
|
|
|
}
|