2018-11-27 07:59:16 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-11-27 07:59:16 +01:00
|
|
|
|
|
|
|
namespace App\Jobs\Client;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Client;
|
2019-01-26 10:34:38 +01:00
|
|
|
use App\Repositories\ClientContactRepository;
|
2018-11-27 07:59:16 +01:00
|
|
|
use App\Repositories\ClientRepository;
|
2019-01-26 10:34:38 +01:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-11-27 07:59:16 +01:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Http\Request;
|
2019-01-26 10:34:38 +01:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-11-27 07:59:16 +01:00
|
|
|
|
|
|
|
class UpdateClient
|
|
|
|
{
|
|
|
|
use Dispatchable;
|
|
|
|
|
2019-05-10 08:08:33 +02:00
|
|
|
protected $data;
|
2018-11-27 07:59:16 +01:00
|
|
|
|
|
|
|
protected $client;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2019-05-10 08:08:33 +02:00
|
|
|
public function __construct(array $data, Client $client)
|
2018-11-27 07:59:16 +01:00
|
|
|
{
|
2019-05-10 08:08:33 +02:00
|
|
|
$this->data = $data;
|
2018-11-27 07:59:16 +01:00
|
|
|
$this->client = $client;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-05-10 08:08:33 +02:00
|
|
|
public function handle(ClientRepository $client_repo, ClientContactRepository $client_contact_repo) :?Client
|
2018-11-27 07:59:16 +01:00
|
|
|
{
|
2019-05-10 08:08:33 +02:00
|
|
|
$client = $client_repo->save($this->data, $this->client);
|
2019-01-26 10:34:38 +01:00
|
|
|
|
2019-05-10 08:08:33 +02:00
|
|
|
$contacts = $client_contact_repo->save($data['contacts']), $client);
|
2019-01-26 10:34:38 +01:00
|
|
|
|
2019-01-26 22:24:16 +01:00
|
|
|
return $client->fresh();
|
2018-11-27 07:59:16 +01:00
|
|
|
}
|
|
|
|
}
|