1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* UserController |
5
|
|
|
* |
6
|
|
|
* This is the controller of users of the shop |
7
|
|
|
* @author Matthijs Neijenhuijs <matthijs@io> |
8
|
|
|
* @version 0.1 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use App\Http\Controllers\Controller; |
12
|
|
|
|
13
|
|
|
use Hideyo\Ecommerce\Framework\Services\User\UserFacade as UserService; |
14
|
|
|
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService; |
15
|
|
|
use Illuminate\Http\Request; |
16
|
|
|
use Notification; |
17
|
|
|
use DataTables; |
18
|
|
|
use Form; |
19
|
|
|
|
20
|
|
|
class UserController extends Controller |
21
|
|
|
{ |
22
|
|
|
public function index(Request $request) |
23
|
|
|
{ |
24
|
|
|
if ($request->wantsJson()) { |
25
|
|
|
$query = UserService::getModel()->select(['id','email', 'username']); |
26
|
|
|
$datatables = DataTables::of($query)->addColumn('action', function ($query) { |
27
|
|
|
$deleteLink = Form::deleteajax(url()->route('user.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
28
|
|
|
$links = '<a href="'.url()->route('user.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
29
|
|
|
|
30
|
|
|
return $links; |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
return $datatables->make(true); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return view('backend.user.index'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function create() |
40
|
|
|
{ |
41
|
|
|
$shops = ShopService::selectAll()->pluck('title', 'id'); |
42
|
|
|
return view('backend.user.create', array('shops' => $shops)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function store(Request $request) |
46
|
|
|
{ |
47
|
|
|
$result = UserService::signup($request->all()); |
48
|
|
|
return UserService::notificationRedirect('user.index', $result, 'The user was inserted.'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function edit($id) |
52
|
|
|
{ |
53
|
|
|
$shops = ShopService::selectAll()->pluck('title', 'id'); |
54
|
|
|
return view('backend.user.edit')->with(array('user' => UserService::find($id), 'shops' => $shops)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function changeShopProfile($shopId) |
58
|
|
|
{ |
59
|
|
|
if (auth('hideyobackend')->user()) { |
60
|
|
|
$id = auth('hideyobackend')->id(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$shop = ShopService::find($shopId); |
64
|
|
|
$result = UserService::updateShopProfileById($shop, $id); |
|
|
|
|
65
|
|
|
Notification::success('The shop changed.'); |
66
|
|
|
return redirect()->route('shop.index'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function update(Request $request, $id) |
70
|
|
|
{ |
71
|
|
|
$result = UserService::updateById($request->all(), $request->file('avatar'), $id); |
72
|
|
|
return UserService::notificationRedirect('user.index', $result, 'The user was updated.'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function destroy($id) |
76
|
|
|
{ |
77
|
|
|
$result = UserService::destroy($id); |
78
|
|
|
|
79
|
|
|
if ($result) { |
80
|
|
|
Notification::success('The user was deleted.'); |
81
|
|
|
return redirect()->route('user.index'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|