akaunting/app/Abstracts/Factory.php

40 lines
827 B
PHP
Raw Normal View History

2020-10-14 17:07:59 +03:00
<?php
namespace App\Abstracts;
use App\Models\Auth\User;
2020-12-24 01:28:38 +03:00
use App\Models\Common\Company;
2020-10-14 17:07:59 +03:00
use App\Traits\Jobs;
use Illuminate\Database\Eloquent\Factories\Factory as BaseFactory;
2020-12-24 01:28:38 +03:00
use Illuminate\Database\Eloquent\Model as EloquentModel;
2020-10-14 17:07:59 +03:00
abstract class Factory extends BaseFactory
{
use Jobs;
2020-12-24 01:28:38 +03:00
/**
* @var Company
*/
protected $company;
/**
* @var User|EloquentModel|object|null
*/
protected $user;
2020-10-16 18:28:10 +03:00
public function __construct(...$arguments)
2020-10-14 17:07:59 +03:00
{
2020-10-16 18:28:10 +03:00
parent::__construct(...$arguments);
2020-10-15 00:27:40 +03:00
2020-10-14 17:07:59 +03:00
$this->user = User::first();
$this->company = $this->user->companies()->first();
2021-04-16 00:59:43 +03:00
company($this->company->id)->makeCurrent();
2020-10-14 17:07:59 +03:00
}
public function getCompanyUsers()
{
return $this->company->users()->enabled()->get()->pluck('id')->toArray();
}
}