-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdc579c
commit 6f0374d
Showing
5 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Customers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Customer\Profile as Request; | ||
use App\Models\Auth\User; | ||
|
||
class Profile extends Controller | ||
{ | ||
|
||
public function index() | ||
{ | ||
return $this->edit(); | ||
} | ||
|
||
public function show() | ||
{ | ||
return $this->edit(); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @return Response | ||
*/ | ||
public function edit() | ||
{ | ||
$user = auth()->user(); | ||
|
||
return view('customers.profile.edit', compact('user')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function update(Request $request) | ||
{ | ||
$user = auth()->user(); | ||
|
||
// Upload picture | ||
$picture = $request->file('picture'); | ||
if ($picture && $picture->isValid()) { | ||
$request['picture'] = $picture->store('users'); | ||
} | ||
|
||
// Do not reset password if not entered/changed | ||
if (empty($request['password'])) { | ||
unset($request['password']); | ||
unset($request['password_confirmation']); | ||
} | ||
|
||
// Update user | ||
$user->update($request->input()); | ||
|
||
// Update customer | ||
$user->customer->update($request->input()); | ||
|
||
$message = trans('messages.success.updated', ['type' => trans('auth.profile')]); | ||
|
||
flash($message)->success(); | ||
|
||
return redirect('customers/profile/edit'); | ||
} | ||
|
||
/** | ||
* Mark overdue invoices notifications are read and redirect to invoices page. | ||
* | ||
* @return Response | ||
*/ | ||
public function readOverdueInvoices() | ||
{ | ||
$user = auth()->user(); | ||
|
||
// Mark invoice notifications as read | ||
foreach ($user->unreadNotifications as $notification) { | ||
// Not an invoice notification | ||
if ($notification->getAttribute('type') != 'App\Notifications\Income\Invoice') { | ||
continue; | ||
} | ||
|
||
$notification->markAsRead(); | ||
} | ||
|
||
// Redirect to invoices | ||
return redirect('customers/invoices'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Customer; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class Profile extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
$id = auth()->user()->getAttribute('id'); | ||
|
||
return [ | ||
'name' => 'required|string', | ||
'email' => 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL', | ||
'password' => 'confirmed', | ||
'picture' => 'mimes:' . setting('general.file_types') . '|between:0,' . setting('general.file_size') * 1024, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@extends('layouts.customer') | ||
|
||
@section('title', trans('general.title.edit', ['type' => trans('auth.profile')])) | ||
|
||
@section('content') | ||
<!-- Default box --> | ||
<div class="box box-success"> | ||
{!! Form::model($user, [ | ||
'method' => 'PATCH', | ||
'files' => true, | ||
'url' => ['customers/profile/update'], | ||
'role' => 'form' | ||
]) !!} | ||
|
||
<div class="box-body"> | ||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }} | ||
|
||
{{ Form::emailGroup('email', trans('general.email'), 'envelope') }} | ||
|
||
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }} | ||
|
||
{{ Form::textGroup('phone', trans('general.phone'), 'phone', []) }} | ||
|
||
{{ Form::textareaGroup('address', trans('general.address')) }} | ||
|
||
{{ Form::passwordGroup('password', trans('auth.password.current'), 'key', []) }} | ||
|
||
{{ Form::passwordGroup('password_confirmation', trans('auth.password.current_confirm'), 'key', []) }} | ||
|
||
{{ Form::selectGroup('locale', trans_choice('general.languages', 1), 'flag', language()->allowed()) }} | ||
|
||
{{ Form::fileGroup('picture', trans_choice('general.pictures', 1)) }} | ||
</div> | ||
<!-- /.box-body --> | ||
|
||
@permission(['update-customers-profile']) | ||
<div class="box-footer"> | ||
{{ Form::saveButtons('customers') }} | ||
</div> | ||
<!-- /.box-footer --> | ||
@endpermission | ||
|
||
{!! Form::close() !!} | ||
</div> | ||
@endsection | ||
|
||
@push('js') | ||
<script src="{{ asset('public/js/bootstrap-fancyfile.js') }}"></script> | ||
@endpush | ||
|
||
@push('css') | ||
<link rel="stylesheet" href="{{ asset('public/css/bootstrap-fancyfile.css') }}"> | ||
@endpush | ||
|
||
@push('scripts') | ||
<script type="text/javascript"> | ||
$(document).ready(function(){ | ||
$("#locale").select2({ | ||
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.languages', 1)]) }}" | ||
}); | ||
$('#picture').fancyfile({ | ||
text : '{{ trans('general.form.select.file') }}', | ||
style : 'btn-default', | ||
placeholder : '<?php echo $user->picture; ?>' | ||
}); | ||
}); | ||
</script> | ||
@endpush |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters