1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Jobs/Company/CreateCompanyToken.php
2019-05-11 13:32:07 +10:00

62 lines
1.4 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\Jobs\Company;
use App\Models\Company;
use App\Models\CompanyToken;
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
*/
public function handle() : ?CompanyToken
{
$ct = CompanyToken::create([
'user_id' => $this->user->id,
'account_id' => $this->company->account->id,
'token' => str_random(64),
'name' => $this->user->first_name. ' '. $this->user->last_name,
'company_id' => $this->company->id,
]);
return $ct;
}
}