1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Repositories/UserRepository.php
David Bomba f712b789ca
Fixes for tests (#3184)
* fix typo

* php-cs traits

* CS fixer pass

* Password protect User routes

* Implement checks to prevent editing a deleted record

* Clean up payment flows

* Fixes for tests
2019-12-31 08:59:12 +11:00

70 lines
1.7 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Repositories;
use App\Models\User;
use App\Models\CompanyUser;
use App\Factory\CompanyUserFactory;
use Illuminate\Http\Request;
/**
* UserRepository
*/
class UserRepository extends BaseRepository
{
public function __construct()
{
}
/**
* Gets the class name.
*
* @return string The class name.
*/
public function getClassName()
{
return User::class;
}
/**
* Saves the user and its contacts
*
* @param array $data The data
* @param \App\Models\user $user The user
*
* @return user|\App\Models\user|null user Object
*/
public function save(array $data, User $user) : ?User
{
$user->fill($data);
$user->save();
if (isset($data['company_user'])) {
$company = auth()->user()->company();
$account_id = $company->account->id;
$cu = CompanyUser::whereUserId($user->id)->whereCompanyId($company->id)->first();
/*No company user exists - attach the user*/
if (!$cu) {
$data['company_user']['account_id'] = $account_id;
$user->companies()->attach($company->id, $data['company_user']);
} else {
$cu->fill($data['company_user']);
$cu->save();
}
}
return $user;
}
}