|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\CMS\Events\Users\ProfileWasUpdated; |
|
6
|
|
|
use Yajra\CMS\Http\Requests\ProfileFormRequest; |
|
7
|
|
|
|
|
8
|
|
|
class ProfileController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Show the form for editing the specified resource. |
|
12
|
|
|
* |
|
13
|
|
|
* @return \Illuminate\Http\Response |
|
14
|
|
|
*/ |
|
15
|
|
|
public function edit() |
|
16
|
|
|
{ |
|
17
|
|
|
return view('administrator.profile.edit'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Update the specified resource in storage. |
|
22
|
|
|
* |
|
23
|
|
|
* @param \Yajra\CMS\Http\Requests\ProfileFormRequest $request |
|
24
|
|
|
* @return \Illuminate\Http\Response |
|
25
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function update(ProfileFormRequest $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$profile = $request->user(); |
|
30
|
|
|
$profile->fill($request->only(['first_name', 'last_name', 'email'])); |
|
31
|
|
|
|
|
32
|
|
|
if ($request->get('password')) { |
|
33
|
|
|
$profile->password = bcrypt($request->get('password')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ((null !== $request->file('avatar')) && $request->file('avatar')->isValid()) { |
|
37
|
|
|
$fileType = $request->file('avatar')->getClientOriginalExtension(); |
|
38
|
|
|
$filename = auth()->user()->id . '-' . $request->file('avatar')->getFilename() . '.' . $fileType; |
|
|
|
|
|
|
39
|
|
|
$request->file('avatar')->move('media/avatar', $filename); |
|
40
|
|
|
$profile->avatar = url('media/avatar/' . $filename); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$profile->save(); |
|
44
|
|
|
|
|
45
|
|
|
event(new ProfileWasUpdated($profile)); |
|
46
|
|
|
|
|
47
|
|
|
flash()->success(trans('cms::profile.alert.success')); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
return redirect()->route('administrator.profile.edit'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Remove current user's avatar. |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
56
|
|
|
*/ |
|
57
|
|
|
public function removeAvatar() |
|
58
|
|
|
{ |
|
59
|
|
|
$profile = auth()->user(); |
|
|
|
|
|
|
60
|
|
|
$profile->avatar = ''; |
|
61
|
|
|
$profile->save(); |
|
62
|
|
|
|
|
63
|
|
|
event(new ProfileWasUpdated($profile)); |
|
64
|
|
|
|
|
65
|
|
|
return redirect()->route('administrator.profile.edit'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param \Yajra\CMS\Http\Requests\ProfileFormRequest $request |
|
70
|
|
|
* @return string |
|
71
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getFilename(ProfileFormRequest $request) |
|
74
|
|
|
{ |
|
75
|
|
|
$fileName = $request->user()->id . '.' . $request->file('avatar')->getClientOriginalExtension(); |
|
76
|
|
|
|
|
77
|
|
|
return $fileName; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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: