2018-06-25 11:00:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\User\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-07-02 09:29:27 +00:00
|
|
|
use Webkul\User\Models\Admin;
|
|
|
|
|
use Webkul\User\Models\Role;
|
|
|
|
|
use Webkul\User\Http\Requests\UserForm;
|
2018-06-25 11:00:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Admin user controller
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class UserController extends Controller
|
|
|
|
|
{
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2018-06-25 11:00:42 +00:00
|
|
|
protected $_config;
|
|
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-06-25 11:00:42 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
|
|
|
|
|
$this->middleware('guest', ['except' => 'destroy']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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-02 09:29:27 +00:00
|
|
|
$roles = Role::all();
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('roles'));
|
2018-06-25 11:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
2018-07-02 09:29:27 +00:00
|
|
|
* @param \Webkul\User\Http\Requests\UserForm $request
|
2018-06-25 11:00:42 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-07-02 09:29:27 +00:00
|
|
|
public function store(UserForm $request)
|
2018-06-25 11:00:42 +00:00
|
|
|
{
|
2018-07-02 09:29:27 +00:00
|
|
|
Admin::create(request()->all());
|
2018-06-25 11:00:42 +00:00
|
|
|
|
2018-07-02 09:29:27 +00:00
|
|
|
session()->flash('success', 'User created successfully.');
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-06-25 11:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
2018-07-02 09:29:27 +00:00
|
|
|
$user = Admin::findOrFail($id);
|
|
|
|
|
$roles = Role::all();
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('user', 'roles'));
|
2018-06-25 11:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
2018-07-02 09:29:27 +00:00
|
|
|
* @param \Webkul\User\Http\Requests\UserForm $request
|
2018-06-25 11:00:42 +00:00
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-07-02 09:29:27 +00:00
|
|
|
public function update(UserForm $request, $id)
|
2018-06-25 11:00:42 +00:00
|
|
|
{
|
2018-07-02 09:29:27 +00:00
|
|
|
$user = Admin::findOrFail($id);
|
|
|
|
|
|
|
|
|
|
$user->update(request(['name', 'email', 'password']));
|
|
|
|
|
|
|
|
|
|
session()->flash('success', 'User updated successfully.');
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
2018-06-25 11:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|