diff --git a/app/Http/Controllers/Customers/Profile.php b/app/Http/Controllers/Customers/Profile.php new file mode 100644 index 000000000..b75ad6d17 --- /dev/null +++ b/app/Http/Controllers/Customers/Profile.php @@ -0,0 +1,92 @@ +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'); + } +} diff --git a/app/Http/Requests/Customer/Profile.php b/app/Http/Requests/Customer/Profile.php new file mode 100644 index 000000000..45b729745 --- /dev/null +++ b/app/Http/Requests/Customer/Profile.php @@ -0,0 +1,35 @@ +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, + ]; + } +} diff --git a/resources/views/customers/profile/edit.blade.php b/resources/views/customers/profile/edit.blade.php new file mode 100644 index 000000000..aaf544b35 --- /dev/null +++ b/resources/views/customers/profile/edit.blade.php @@ -0,0 +1,69 @@ +@extends('layouts.customer') + +@section('title', trans('general.title.edit', ['type' => trans('auth.profile')])) + +@section('content') + +
+ {!! Form::model($user, [ + 'method' => 'PATCH', + 'files' => true, + 'url' => ['customers/profile/update'], + 'role' => 'form' + ]) !!} + +
+ {{ 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)) }} +
+ + + @permission(['update-customers-profile']) + + + @endpermission + + {!! Form::close() !!} +
+@endsection + +@push('js') + +@endpush + +@push('css') + +@endpush + +@push('scripts') + +@endpush diff --git a/resources/views/partials/customer/header.blade.php b/resources/views/partials/customer/header.blade.php index 8a6d3ef01..27d5c3437 100644 --- a/resources/views/partials/customer/header.blade.php +++ b/resources/views/partials/customer/header.blade.php @@ -31,17 +31,10 @@