2019-08-02 02:31:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. 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-12 14:45:13 +02:00
|
|
|
use App\Http\Requests\ClientPortal\UpdateContactRequest;
|
2019-08-14 02:15:21 +02:00
|
|
|
use App\Http\Requests\ClientPortal\UpdateClientRequest;
|
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;
|
|
|
|
use Illuminate\Http\Request;
|
2019-08-13 01:56:46 +02:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
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
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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
|
|
|
|
* @return \Illuminate\Http\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-12-30 22:59:12 +01:00
|
|
|
}
|
2019-08-13 01:56:46 +02:00
|
|
|
|
|
|
|
$client_contact->save();
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
// 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
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($request->file('logo')) {
|
2019-08-26 11:28:21 +02:00
|
|
|
$path = UploadAvatar::dispatchNow($request->file('logo'), auth()->user()->client->client_hash);
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($path) {
|
2019-08-26 11:28:21 +02:00
|
|
|
$client->logo = $path;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
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
|
|
|
}
|