|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Back; |
|
4
|
|
|
|
|
5
|
|
|
use App\Services\Auth\Front\Enums\UserRole; |
|
6
|
|
|
use App\Services\Auth\Front\Enums\UserStatus; |
|
7
|
|
|
use App\Services\Auth\Front\Events\UserCreatedThroughBack; |
|
8
|
|
|
use App\Http\Requests\Back\FrontUserRequest; |
|
9
|
|
|
use App\Services\Auth\Front\User; |
|
10
|
|
|
use App\Services\Auth\Front\UserUpdater; |
|
11
|
|
|
use App\Repositories\FrontUserRepository; |
|
12
|
|
|
|
|
13
|
|
|
class MembersController |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var \App\Repositories\FrontUserRepository */ |
|
16
|
|
|
protected $frontUserRepository; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(FrontUserRepository $frontUserRepository) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->frontUserRepository = $frontUserRepository; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function index() |
|
24
|
|
|
{ |
|
25
|
|
|
$users = $this->frontUserRepository->getAll(); |
|
26
|
|
|
|
|
27
|
|
|
return view('back.members.index')->with(compact('users')); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function create() |
|
31
|
|
|
{ |
|
32
|
|
|
return view('back.members.create', ['user' => new User()]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function store(FrontUserRequest $request) |
|
36
|
|
|
{ |
|
37
|
|
|
$user = new User(); |
|
38
|
|
|
|
|
39
|
|
|
$user->email = $request->get('email'); |
|
40
|
|
|
$user->first_name = $request->get('first_name'); |
|
41
|
|
|
$user->last_name = $request->get('last_name'); |
|
42
|
|
|
$user->locale = $request->get('locale', 'nl'); |
|
43
|
|
|
|
|
44
|
|
|
$user->role = UserRole::MEMBER(); |
|
45
|
|
|
$user->status = UserStatus::ACTIVE(); |
|
46
|
|
|
|
|
47
|
|
|
$this->frontUserRepository->save($user); |
|
48
|
|
|
|
|
49
|
|
|
$eventDescription = $this->getEventDescriptionFor('created', $user); |
|
50
|
|
|
activity($eventDescription); |
|
51
|
|
|
flash()->success(strip_tags($eventDescription).'. '.fragment('back.members.passwordMailSent')); |
|
52
|
|
|
|
|
53
|
|
|
event(new UserCreatedThroughBack($user)); |
|
54
|
|
|
|
|
55
|
|
|
return redirect()->action('Back\MembersController@index'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function edit($id) |
|
59
|
|
|
{ |
|
60
|
|
|
$user = $this->frontUserRepository->find($id); |
|
61
|
|
|
|
|
62
|
|
|
if (!$user) { |
|
63
|
|
|
abort(404); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return view('back.members.edit')->with(compact('user')); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function update($id, FrontUserRequest $request) |
|
70
|
|
|
{ |
|
71
|
|
|
abort_unless($user = $this->frontUserRepository->find($id), 500); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$user->email = $request->get('email'); |
|
74
|
|
|
$user->first_name = $request->get('first_name'); |
|
75
|
|
|
$user->last_name = $request->get('last_name'); |
|
76
|
|
|
$user->locale = $request->get('locale', 'nl'); |
|
77
|
|
|
|
|
78
|
|
|
$this->frontUserRepository->save($user); |
|
79
|
|
|
|
|
80
|
|
|
$eventDescription = $this->getEventDescriptionFor('updated', $user); |
|
81
|
|
|
activity()->on($user)->log($eventDescription); |
|
82
|
|
|
flash()->success(strip_tags($eventDescription)); |
|
83
|
|
|
|
|
84
|
|
|
return redirect()->action('Back\MembersController@index'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
View Code Duplication |
public function destroy($id) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
$user = $this->frontUserRepository->find($id); |
|
90
|
|
|
|
|
91
|
|
|
$this->frontUserRepository->delete($user); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$eventDescription = $this->getEventDescriptionFor('deleted', $user); |
|
|
|
|
|
|
94
|
|
|
activity()->log($eventDescription); |
|
95
|
|
|
flash()->success(strip_tags($eventDescription)); |
|
96
|
|
|
|
|
97
|
|
|
return redirect()->action('Back\MembersController@index'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
View Code Duplication |
protected function getEventDescriptionFor(string $event, User $user): string |
|
|
|
|
|
|
101
|
|
|
{ |
|
102
|
|
|
$name = sprintf( |
|
103
|
|
|
'<a href="%s">%s</a>', |
|
104
|
|
|
action('Back\MembersController@edit', [$user->id]), |
|
105
|
|
|
$user->email |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
if ($event === 'deleted') { |
|
109
|
|
|
$name = $user->email; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return trans("back.events.$event", ['model' => fragment('back.members.member'), 'name' => $name]); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: