|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\CMS\Http\Requests\ProfileFormRequest; |
|
6
|
|
|
use App\Http\Requests; |
|
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
|
|
|
$filename = $this->getFilename($request); |
|
38
|
|
|
$request->file('avatar')->move('img/avatar', $filename); |
|
39
|
|
|
$profile->avatar = url('img/avatar/' . $filename); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$profile->save(); |
|
43
|
|
|
|
|
44
|
|
|
flash()->success(trans('cms::profile.alert.success')); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
return redirect()->route('administrator.profile.edit'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \Yajra\CMS\Http\Requests\ProfileFormRequest $request |
|
51
|
|
|
* @return string |
|
52
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function getFilename(ProfileFormRequest $request) |
|
55
|
|
|
{ |
|
56
|
|
|
$fileName = $request->user()->id . '.' . $request->file('avatar')->getClientOriginalExtension(); |
|
57
|
|
|
|
|
58
|
|
|
return $fileName; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Remove current user's avatar. |
|
63
|
|
|
* |
|
64
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
65
|
|
|
*/ |
|
66
|
|
|
public function removeAvatar() |
|
67
|
|
|
{ |
|
68
|
|
|
$profile = auth()->user(); |
|
|
|
|
|
|
69
|
|
|
$profile->avatar = ''; |
|
70
|
|
|
$profile->save(); |
|
71
|
|
|
|
|
72
|
|
|
return redirect()->route('administrator.profile.edit'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.