Skip to content

Commit 5738743

Browse files
committed
add admin picture with manage it in panel->edit
1 parent ee14446 commit 5738743

File tree

3 files changed

+94
-45
lines changed

3 files changed

+94
-45
lines changed

src/controllers/ProfileController.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,28 @@
33

44
use Illuminate\Routing\Controller;
55
use Illuminate\Support\Facades\Input;
6+
use Illuminate\Support\Facades\File;
67

78
class ProfileController extends Controller {
89

910
public function getEdit() {
1011

11-
$admin = Admin::find(\Auth::guard('panel')->user()->id);
12+
$admin = Admin::find(\Auth::guard('panel')->user()->id);
1213

13-
$demo = false;
14-
if (\Config::get('panel.demo') == true) {
15-
$demo = true;
16-
}
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+
}
1728

1829
return \View('panelViews::editProfile')->with('admin', $admin)->with('demo_status', $demo);
1930
}
@@ -22,18 +33,39 @@ public function postEdit() {
2233

2334
$demo = false;
2435
if (\Config::get('panel.demo') == true) {
25-
$demo = true;
36+
$demo = true;
2637
}
2738

2839
$admin = Admin::find(\Auth::guard('panel')->user()->id);
2940
$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']);
3062
$admin->update($inputs);
3163
$admin->save();
3264
return \View('panelViews::editProfile')->with(
3365
array(
34-
'admin' => $admin,
35-
'message' => \Lang::get('panel::fields.successfullEditProfile'),
36-
'demo_status' => $demo)
66+
'admin' => $admin,
67+
'message' => \Lang::get('panel::fields.successfullEditProfile'),
68+
'demo_status' => $demo)
3769
);
3870
}
3971
}

src/views/editProfile.blade.php

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,50 @@
22
@extends('panelViews::mainTemplate')
33
@section('page-wrapper')
44

5-
@if (!empty($message))
6-
<div class="alert-box success">
7-
<h2>{{ $message }}</h2>
8-
</div>
9-
@endif
10-
11-
@if ($demo_status == true)
12-
<h4>You are not allowed to edit the profile in demo version of panel.</h4>
13-
@else
14-
15-
<div class="row">
16-
<div class="col-xs-4" >
17-
<div class="well well-lg">
18-
{!!
19-
Form::model($admin, array( $admin->id))
20-
!!}
21-
22-
{!! Form::label('first_name', \Lang::get('panel::fields.FirstName')) !!}
23-
{!! Form::text('first_name', $admin->first_name, array('class' => 'form-control')) !!}
24-
<br />
25-
{!! Form::label('last_name', \Lang::get('panel::fields.LastName')) !!}
26-
{!! Form::text('last_name', $admin->last_name, array('class' => 'form-control')) !!}
27-
<br />
28-
<!-- email -->
29-
{!! Form::label('email', \Lang::get('panel::fields.email')) !!}
30-
{!! Form::email('email', $admin->email, array('class' => 'form-control')) !!}
31-
<br />
32-
{!! Form::submit(\Lang::get('panel::fields.updateProfile'), array('class' => 'btn btn-primary')) !!}
33-
34-
{!! Form::close() !!}
35-
</div>
36-
@endif
37-
38-
</div>
39-
</div>
5+
@if (!empty($message))
6+
<div class="alert-box success">
7+
<h2>{{ $message }}</h2>
8+
</div>
9+
@endif
10+
11+
@if ($demo_status == true)
12+
<h4>You are not allowed to edit the profile in demo version of panel.</h4>
13+
@else
14+
15+
<div class="row">
16+
<div class="col-xs-4" >
17+
<div class="well well-lg">
18+
{!!
19+
Form::model($admin, array( $admin->id, 'files' => true))
20+
!!}
21+
22+
{!! Form::label('first_name', \Lang::get('panel::fields.FirstName')) !!}
23+
{!! Form::text('first_name', $admin->first_name, array('class' => 'form-control')) !!}
24+
<br />
25+
{!! Form::label('last_name', \Lang::get('panel::fields.LastName')) !!}
26+
{!! Form::text('last_name', $admin->last_name, array('class' => 'form-control')) !!}
27+
<br />
28+
<!-- email -->
29+
{!! Form::label('email', \Lang::get('panel::fields.email')) !!}
30+
{!! Form::email('email', $admin->email, array('class' => 'form-control')) !!}
31+
<br />
32+
@if (!empty($admin->getAdminPicture()))
33+
<img src="{{ asset($admin->getAdminPicture()) }}" alt="{{$admin->first_name}} {{$admin->last_name}}" style="width: 60px; height: 60px; border-radius: 50%;" />
34+
<a href="?del_picture=1">delete</a>
35+
@else
36+
<!-- file of picture -->
37+
{!! Form::label('picture', \Lang::get('panel::fields.picture')) !!}
38+
{!! Form::file('picture') !!}
39+
@endif
40+
<br />
41+
<br />
42+
{!! Form::submit(\Lang::get('panel::fields.updateProfile'), array('class' => 'btn btn-primary')) !!}
43+
44+
{!! Form::close() !!}
45+
</div>
46+
@endif
47+
48+
</div>
49+
</div>
4050

4151
@stop

src/views/mainTemplate.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@
3737

3838
<div class="navbar-default sidebar " role="navigation">
3939
<div class="sidebar-nav navbar-collapse collapse " id="bs-example-navbar-collapse-1">
40-
<div class="grav center"><img src="//www.gravatar.com/avatar/{{ md5( strtolower( trim( Auth::guard('panel')->user()->email ) ) )}}?d=mm&s=128" ><a href="{{url('panel/edit')}}"><span> {{ \Lang::get('panel::fields.change') }}</span></a></div>
40+
<div class="grav center">
41+
@if (!empty(Auth::guard('panel')->user()->getAdminPicture()))
42+
<img src="{{ asset(Auth::guard('panel')->user()->getAdminPicture()) }}" />
43+
@else
44+
<img src="//www.gravatar.com/avatar/{{ md5( strtolower( trim( Auth::guard('panel')->user()->email ) ) )}}?d=mm&s=128" />
45+
@endif
46+
<a href="{{url('panel/edit')}}"><span> {{ \Lang::get('panel::fields.change') }}</span></a>
47+
</div>
4148
<div class="user-info">{{Auth::guard('panel')->user()->first_name.' '.Auth::guard('panel')->user()->last_name}}</div>
4249
<a class="visit-site" href="{{$app['url']->to('/')}}">{{ \Lang::get('panel::fields.visiteSite') }} </a>
4350
<ul class="nav" id="side-menu">

0 commit comments

Comments
 (0)