|
1
|
|
|
<?php |
|
2
|
|
|
namespace Serverfireteam\Panel; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Routing\Controller; |
|
5
|
|
|
use Illuminate\Support\Facades\Input; |
|
6
|
|
|
use Illuminate\Support\Facades\File; |
|
7
|
|
|
|
|
8
|
|
|
class ProfileController extends Controller { |
|
9
|
|
|
|
|
10
|
|
|
public function getEdit() { |
|
11
|
|
|
|
|
12
|
|
|
$admin = Admin::find(\Auth::guard('panel')->user()->id); |
|
13
|
|
|
|
|
14
|
|
|
$demo = false; |
|
15
|
|
|
if (\Config::get('panel.demo') == true) { |
|
16
|
|
|
$demo = true; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
if (!$demo && request()->has('del_picture')){ |
|
20
|
|
|
$file = $admin->getAdminPicture(); |
|
21
|
|
|
//dd(public_path($file)); |
|
22
|
|
|
if (!empty($file) && File::exists(public_path($file))){ |
|
23
|
|
|
File::delete(public_path($file)); |
|
24
|
|
|
} |
|
25
|
|
|
$admin->updateAdminPicture(''); |
|
26
|
|
|
return \Redirect::to(request()->path()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return \View('panelViews::editProfile')->with('admin', $admin)->with('demo_status', $demo); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function postEdit() { |
|
33
|
|
|
|
|
34
|
|
|
$demo = false; |
|
35
|
|
|
if (\Config::get('panel.demo') == true) { |
|
36
|
|
|
$demo = true; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$admin = Admin::find(\Auth::guard('panel')->user()->id); |
|
40
|
|
|
$inputs = Input::all(); |
|
41
|
|
|
request()->validate([ |
|
42
|
|
|
'picture' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048', |
|
43
|
|
|
]); |
|
44
|
|
|
// Check if a profile image has been uploaded |
|
45
|
|
|
if (request()->has('picture')) { |
|
46
|
|
|
// Get image file |
|
47
|
|
|
$image = request()->file('picture'); |
|
48
|
|
|
// Make a image name based on user name and current timestamp |
|
49
|
|
|
$name = str_slug(request()->input('first_name')).'_'.str_slug(request()->input('last_name')).'_'.time(); |
|
|
|
|
|
|
50
|
|
|
// Define folder path |
|
51
|
|
|
$folder = '/uploads/panel_avatars/'; |
|
52
|
|
|
// Make a file path where image will be stored [ folder path + file name + file extension] |
|
53
|
|
|
$filePath = $folder . $name. '.' . $image->getClientOriginalExtension(); |
|
54
|
|
|
// Upload image |
|
55
|
|
|
$name = !empty($name) ? $name : str_random(25); |
|
|
|
|
|
|
56
|
|
|
$file = $image->move(public_path($folder), $name.'.'.$image->getClientOriginalExtension()); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
// Set user profile image path in database to filePath |
|
59
|
|
|
$admin->updateAdminPicture($filePath); |
|
60
|
|
|
} |
|
61
|
|
|
//dd($inputs['picture']); |
|
62
|
|
|
$admin->update($inputs); |
|
63
|
|
|
$admin->save(); |
|
64
|
|
|
return \View('panelViews::editProfile')->with( |
|
65
|
|
|
array( |
|
66
|
|
|
'admin' => $admin, |
|
67
|
|
|
'message' => \Lang::get('panel::fields.successfullEditProfile'), |
|
68
|
|
|
'demo_status' => $demo) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.