1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/ProfileController.php

81 lines
2.1 KiB
PHP
Raw Normal View History

2019-08-02 02:31:48 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-08-02 02:31:48 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-08-02 02:31:48 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
2019-08-14 02:15:21 +02:00
use App\Http\Requests\ClientPortal\UpdateClientRequest;
use App\Http\Requests\ClientPortal\UpdateContactRequest;
2019-08-13 01:56:46 +02:00
use App\Jobs\Util\UploadAvatar;
2019-08-02 02:31:48 +02:00
use App\Models\ClientContact;
2020-10-28 11:10:49 +01:00
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
2019-08-02 02:31:48 +02: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 11:10:49 +01:00
* @return Factory|View
2019-08-02 02:31:48 +02:00
*/
public function edit(ClientContact $client_contact)
{
2020-03-23 18:10:42 +01:00
return $this->render('profile.index');
2019-08-02 02:31:48 +02: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 11:10:49 +01:00
* @return RedirectResponse
2019-08-02 02:31:48 +02:00
*/
2019-08-12 14:45:13 +02:00
public function update(UpdateContactRequest $request, ClientContact $client_contact)
2019-08-02 02:31:48 +02:00
{
2019-08-13 01:56:46 +02: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 01:56:46 +02:00
$client_contact->save();
// auth()->user()->fresh();
2019-08-13 01:56:46 +02:00
2020-03-23 18:10:42 +01:00
return back()->withSuccess(
ctrans('texts.profile_updated_successfully')
);
2019-08-02 02:31:48 +02:00
}
2019-08-14 02:15:21 +02:00
public function updateClient(UpdateClientRequest $request, ClientContact $client_contact)
2019-08-13 23:16:31 +02:00
{
2019-08-14 02:15:21 +02:00
$client = $client_contact->client;
2019-08-26 11:28:21 +02:00
//update avatar if needed
if ($request->file('logo')) {
2019-08-26 11:28:21 +02:00
$path = UploadAvatar::dispatchNow($request->file('logo'), auth()->user()->client->client_hash);
if ($path) {
2019-08-26 11:28:21 +02:00
$client->logo = $path;
}
2019-08-26 11:28:21 +02:00
}
2019-08-14 02:15:21 +02: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-13 23:16:31 +02:00
}
2019-08-02 02:31:48 +02:00
}