1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00
invoiceninja/app/Jobs/Company/CreateCompanyToken.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2019-03-26 05:46:08 +01:00
<?php
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;
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-03-26 05:46:08 +01: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
}
}