2019-03-26 05:46:08 +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
|
|
|
|
*/
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
namespace App\Jobs\Company;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
2019-03-26 22:17:28 +01:00
|
|
|
use App\Models\CompanyToken;
|
2019-03-26 05:46:08 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2019-09-26 15:00:51 +02:00
|
|
|
use Illuminate\Support\Str;
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
class CreateCompanyToken implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Company $company, User $user)
|
|
|
|
{
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-26 22:17:28 +01:00
|
|
|
public function handle() : ?CompanyToken
|
2019-03-26 05:46:08 +01:00
|
|
|
{
|
2019-03-26 22:17:28 +01:00
|
|
|
|
|
|
|
$ct = CompanyToken::create([
|
2019-03-26 05:46:08 +01:00
|
|
|
'user_id' => $this->user->id,
|
2019-03-26 22:17:28 +01:00
|
|
|
'account_id' => $this->company->account->id,
|
2019-09-26 15:00:51 +02:00
|
|
|
'token' => Str::random(64),
|
2019-03-26 22:17:28 +01:00
|
|
|
'name' => $this->user->first_name. ' '. $this->user->last_name,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $ct;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
}
|