invoiceninja/app/Http/Controllers/ClientPortal/ProfileController.php

81 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2019-08-02 10:31:48 +10:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-08-02 10:31:48 +10:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-08-02 10:31:48 +10:00
*
2021-06-16 16:58:16 +10:00
* @license https://www.elastic.co/licensing/elastic-license
2019-08-02 10:31:48 +10:00
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
2019-08-14 10:15:21 +10:00
use App\Http\Requests\ClientPortal\UpdateClientRequest;
use App\Http\Requests\ClientPortal\UpdateContactRequest;
2019-08-13 09:56:46 +10:00
use App\Jobs\Util\UploadAvatar;
2019-08-02 10:31:48 +10:00
use App\Models\ClientContact;
2020-10-28 21:10:49 +11:00
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
2019-08-02 10:31:48 +10:00
class ProfileController extends Controller
{
/**
* Show the form for editing the specified resource.
*
2020-03-23 18:10:42 +01:00
* @param ClientContact $client_contact
2020-10-28 21:10:49 +11:00
* @return Factory|View
2019-08-02 10:31:48 +10:00
*/
public function edit(ClientContact $client_contact)
{
2020-03-23 18:10:42 +01:00
return $this->render('profile.index');
2019-08-02 10:31:48 +10:00
}
/**
* Update the specified resource in storage.
*
2020-03-23 18:10:42 +01:00
* @param UpdateContactRequest $request
* @param ClientContact $client_contact
2020-10-28 21:10:49 +11:00
* @return RedirectResponse
2019-08-02 10:31:48 +10:00
*/
2019-08-12 22:45:13 +10:00
public function update(UpdateContactRequest $request, ClientContact $client_contact)
2019-08-02 10:31:48 +10:00
{
2019-08-13 09:56:46 +10:00
$client_contact->fill($request->all());
2020-03-23 18:10:42 +01:00
if ($request->has('password')) {
$client_contact->password = encrypt($request->password);
}
2019-08-13 09:56:46 +10:00
$client_contact->save();
// auth()->user()->fresh();
2019-08-13 09:56:46 +10:00
2020-03-23 18:10:42 +01:00
return back()->withSuccess(
ctrans('texts.profile_updated_successfully')
);
2019-08-02 10:31:48 +10:00
}
2019-08-14 10:15:21 +10:00
public function updateClient(UpdateClientRequest $request, ClientContact $client_contact)
2019-08-14 07:16:31 +10:00
{
2019-08-14 10:15:21 +10:00
$client = $client_contact->client;
2019-08-26 19:28:21 +10:00
//update avatar if needed
if ($request->file('logo')) {
2019-08-26 19:28:21 +10:00
$path = UploadAvatar::dispatchNow($request->file('logo'), auth()->user()->client->client_hash);
if ($path) {
2019-08-26 19:28:21 +10:00
$client->logo = $path;
}
2019-08-26 19:28:21 +10:00
}
2019-08-14 10:15:21 +10:00
$client->fill($request->all());
$client->save();
2020-03-23 18:10:42 +01:00
return back()->withSuccess(
ctrans('texts.profile_updated_successfully')
);
2019-08-14 07:16:31 +10:00
}
2019-08-02 10:31:48 +10:00
}