Skip to content

Commit

Permalink
fixed #138
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 16, 2017
1 parent fdc579c commit 6f0374d
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 11 deletions.
92 changes: 92 additions & 0 deletions app/Http/Controllers/Customers/Profile.php
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');
}
}
35 changes: 35 additions & 0 deletions app/Http/Requests/Customer/Profile.php
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,
];
}
}
69 changes: 69 additions & 0 deletions resources/views/customers/profile/edit.blade.php
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
15 changes: 4 additions & 11 deletions resources/views/partials/customer/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
@if (count($bills))
<li>
<a href="{{ url('auth/users/' . $user->id . '/read-bills') }}">
<i class="fa fa-shopping-cart text-red"></i> {{ trans_choice('header.notifications.upcoming_bills', count($bills), ['count' => count($bills)]) }}
</a>
</li>
@endif
@if (count($invoices))
<li>
<a href="{{ url('auth/users/' . $user->id . '/read-invoices') }}">
<i class="fa fa-money text-green"></i> {{ trans_choice('header.notifications.overdue_invoices', count($invoices), ['count' => count($invoices)]) }}
<a href="{{ url('customers/profile/read-invoices') }}">
<i class="fa fa-money text-red"></i> {{ trans_choice('header.notifications.overdue_invoices', count($invoices), ['count' => count($invoices)]) }}
</a>
</li>
@endif
Expand Down Expand Up @@ -92,9 +85,9 @@
</li>
<!-- Menu Footer-->
<li class="user-footer">
@permission('read-customers-profile')
@permission('update-customers-profile')
<div class="pull-left">
<a href="{{ url('auth/users/' . $user->id . '/edit') }}" class="btn btn-default btn-flat">{{ trans('auth.profile') }}</a>
<a href="{{ url('customers/profile/edit') }}" class="btn btn-default btn-flat">{{ trans('auth.profile') }}</a>
</div>
@endpermission
<div class="pull-right">
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
Route::resource('invoices', 'Customers\Invoices');
Route::resource('payments', 'Customers\Payments');
Route::resource('transactions', 'Customers\Transactions');
Route::get('profile/read-invoices', 'Customers\Profile@readOverdueInvoices');
Route::resource('profile', 'Customers\Profile');

Route::get('logout', 'Auth\Login@destroy')->name('customer_logout');
});
Expand Down

0 comments on commit 6f0374d

Please sign in to comment.