Skip to content

Commit

Permalink
add admin picture with manage it in panel->edit
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaAb committed Jun 10, 2019
1 parent ee14446 commit 5738743
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 45 deletions.
50 changes: 41 additions & 9 deletions src/controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\File;

class ProfileController extends Controller {

public function getEdit() {

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

$demo = false;
if (\Config::get('panel.demo') == true) {
$demo = true;
}
$demo = false;
if (\Config::get('panel.demo') == true) {
$demo = true;
}

if (!$demo && request()->has('del_picture')){
$file = $admin->getAdminPicture();
//dd(public_path($file));
if (!empty($file) && File::exists(public_path($file))){
File::delete(public_path($file));
}
$admin->updateAdminPicture('');
return \Redirect::to(request()->path());
}

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

$demo = false;
if (\Config::get('panel.demo') == true) {
$demo = true;
$demo = true;
}

$admin = Admin::find(\Auth::guard('panel')->user()->id);
$inputs = Input::all();
request()->validate([
'picture' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
// Check if a profile image has been uploaded
if (request()->has('picture')) {
// Get image file
$image = request()->file('picture');
// Make a image name based on user name and current timestamp
$name = str_slug(request()->input('first_name')).'_'.str_slug(request()->input('last_name')).'_'.time();
// Define folder path
$folder = '/uploads/panel_avatars/';
// Make a file path where image will be stored [ folder path + file name + file extension]
$filePath = $folder . $name. '.' . $image->getClientOriginalExtension();
// Upload image
$name = !empty($name) ? $name : str_random(25);
$file = $image->move(public_path($folder), $name.'.'.$image->getClientOriginalExtension());

// Set user profile image path in database to filePath
$admin->updateAdminPicture($filePath);
}
//dd($inputs['picture']);
$admin->update($inputs);
$admin->save();
return \View('panelViews::editProfile')->with(
array(
'admin' => $admin,
'message' => \Lang::get('panel::fields.successfullEditProfile'),
'demo_status' => $demo)
'admin' => $admin,
'message' => \Lang::get('panel::fields.successfullEditProfile'),
'demo_status' => $demo)
);
}
}
80 changes: 45 additions & 35 deletions src/views/editProfile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,50 @@
@extends('panelViews::mainTemplate')
@section('page-wrapper')

@if (!empty($message))
<div class="alert-box success">
<h2>{{ $message }}</h2>
</div>
@endif

@if ($demo_status == true)
<h4>You are not allowed to edit the profile in demo version of panel.</h4>
@else

<div class="row">
<div class="col-xs-4" >
<div class="well well-lg">
{!!
Form::model($admin, array( $admin->id))
!!}

{!! Form::label('first_name', \Lang::get('panel::fields.FirstName')) !!}
{!! Form::text('first_name', $admin->first_name, array('class' => 'form-control')) !!}
<br />
{!! Form::label('last_name', \Lang::get('panel::fields.LastName')) !!}
{!! Form::text('last_name', $admin->last_name, array('class' => 'form-control')) !!}
<br />
<!-- email -->
{!! Form::label('email', \Lang::get('panel::fields.email')) !!}
{!! Form::email('email', $admin->email, array('class' => 'form-control')) !!}
<br />
{!! Form::submit(\Lang::get('panel::fields.updateProfile'), array('class' => 'btn btn-primary')) !!}

{!! Form::close() !!}
</div>
@endif

</div>
</div>
@if (!empty($message))
<div class="alert-box success">
<h2>{{ $message }}</h2>
</div>
@endif

@if ($demo_status == true)
<h4>You are not allowed to edit the profile in demo version of panel.</h4>
@else

<div class="row">
<div class="col-xs-4" >
<div class="well well-lg">
{!!
Form::model($admin, array( $admin->id, 'files' => true))
!!}

{!! Form::label('first_name', \Lang::get('panel::fields.FirstName')) !!}
{!! Form::text('first_name', $admin->first_name, array('class' => 'form-control')) !!}
<br />
{!! Form::label('last_name', \Lang::get('panel::fields.LastName')) !!}
{!! Form::text('last_name', $admin->last_name, array('class' => 'form-control')) !!}
<br />
<!-- email -->
{!! Form::label('email', \Lang::get('panel::fields.email')) !!}
{!! Form::email('email', $admin->email, array('class' => 'form-control')) !!}
<br />
@if (!empty($admin->getAdminPicture()))
<img src="{{ asset($admin->getAdminPicture()) }}" alt="{{$admin->first_name}} {{$admin->last_name}}" style="width: 60px; height: 60px; border-radius: 50%;" />
<a href="?del_picture=1">delete</a>
@else
<!-- file of picture -->
{!! Form::label('picture', \Lang::get('panel::fields.picture')) !!}
{!! Form::file('picture') !!}
@endif
<br />
<br />
{!! Form::submit(\Lang::get('panel::fields.updateProfile'), array('class' => 'btn btn-primary')) !!}

{!! Form::close() !!}
</div>
@endif

</div>
</div>

@stop
9 changes: 8 additions & 1 deletion src/views/mainTemplate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@

<div class="navbar-default sidebar " role="navigation">
<div class="sidebar-nav navbar-collapse collapse " id="bs-example-navbar-collapse-1">
<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>
<div class="grav center">
@if (!empty(Auth::guard('panel')->user()->getAdminPicture()))
<img src="{{ asset(Auth::guard('panel')->user()->getAdminPicture()) }}" />
@else
<img src="//www.gravatar.com/avatar/{{ md5( strtolower( trim( Auth::guard('panel')->user()->email ) ) )}}?d=mm&s=128" />
@endif
<a href="{{url('panel/edit')}}"><span> {{ \Lang::get('panel::fields.change') }}</span></a>
</div>
<div class="user-info">{{Auth::guard('panel')->user()->first_name.' '.Auth::guard('panel')->user()->last_name}}</div>
<a class="visit-site" href="{{$app['url']->to('/')}}">{{ \Lang::get('panel::fields.visiteSite') }} </a>
<ul class="nav" id="side-menu">
Expand Down

0 comments on commit 5738743

Please sign in to comment.