1 | <?php |
||||
2 | |||||
3 | namespace App\Jobs\Tenant; |
||||
4 | |||||
5 | use App\Models\Tenant; |
||||
6 | use Illuminate\Bus\Queueable; |
||||
7 | use Illuminate\Contracts\Queue\ShouldQueue; |
||||
8 | use Illuminate\Foundation\Bus\Dispatchable; |
||||
9 | use Illuminate\Queue\InteractsWithQueue; |
||||
10 | use Illuminate\Queue\SerializesModels; |
||||
11 | use Illuminate\Support\Facades\Hash; |
||||
12 | use LaravelEnso\Companies\Models\Company; |
||||
13 | use LaravelEnso\People\Models\Person; |
||||
14 | use LaravelEnso\Roles\Models\Role; |
||||
15 | use LaravelEnso\UserGroups\Models\UserGroup; |
||||
16 | use LaravelEnso\Users\Models\User; |
||||
17 | |||||
18 | class Migration implements ShouldQueue |
||||
19 | { |
||||
20 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
21 | |||||
22 | /** |
||||
23 | * Create a new job instance. |
||||
24 | * |
||||
25 | * @return void |
||||
26 | */ |
||||
27 | public function __construct(private readonly Company $tenant, private $name = '', private $email = '', private $password = '') |
||||
28 | { |
||||
29 | // $this->queue = 'sync'; |
||||
30 | } |
||||
31 | |||||
32 | /** |
||||
33 | * Execute the job. |
||||
34 | * |
||||
35 | * @return void |
||||
36 | */ |
||||
37 | public function handle() |
||||
38 | { |
||||
39 | $tenants = Tenant::find($this->tenant->id); |
||||
40 | |||||
41 | tenancy()->initialize($tenants); |
||||
0 ignored issues
–
show
It seems like
$tenants can also be of type Illuminate\Database\Eloq...gHasThroughRelationship ; however, parameter $tenant of Stancl\Tenancy\Tenancy::initialize() does only seem to accept Stancl\Tenancy\Contracts\Tenant|integer|string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
42 | $em = $this->email; |
||||
43 | $na = $this->name; |
||||
44 | $person = $tenants->run(fn () => Person::create([ |
||||
45 | 'email' => $em, |
||||
46 | 'name' => $na, |
||||
47 | |||||
48 | ])); |
||||
49 | $user_group = $tenants->run(fn () => UserGroup::create([ |
||||
50 | 'name' => 'Administrators', |
||||
51 | 'description' => 'Administrator users group', |
||||
52 | |||||
53 | ])); |
||||
54 | // get role_id |
||||
55 | // $role = 1; |
||||
56 | $role = $tenants->run(fn () => Role::create([ |
||||
57 | 'name' => 'free', |
||||
58 | 'menu_id ' => null, |
||||
59 | 'display_name' => 'Free', |
||||
60 | 'description' => 'Free Role.', |
||||
61 | ])); |
||||
62 | $pa = $this->password; |
||||
63 | $tenants->run(fn () => User::create([ |
||||
64 | 'email' => $em, |
||||
65 | 'password' => Hash::make($pa), |
||||
66 | 'person_id' => $person->id, |
||||
0 ignored issues
–
show
|
|||||
67 | 'group_id' => $user_group->id, |
||||
68 | 'role_id' => $role->id, |
||||
69 | 'is_active' => 1, |
||||
70 | |||||
71 | ])); |
||||
72 | tenancy()->end(); |
||||
73 | // Tenant::set($this->tenant); |
||||
74 | // $company = Tenant::get(); |
||||
75 | // $db = Connections::Tenant.$company->id.'_1'; |
||||
76 | // Artisan::call('migrate', [ |
||||
77 | // '--database' => Connections::Tenant, |
||||
78 | // '--path' => '/database/migrations/tenant', |
||||
79 | // '--force' => true, |
||||
80 | // ]); |
||||
81 | |||||
82 | /** Artisan::call('db:seed', [ |
||||
83 | * '--database' => Connections::Tenant, |
||||
84 | * '--force' => true, |
||||
85 | * ]);. |
||||
86 | */ |
||||
87 | // $person = DB::connection(Connections::Tenant)->table('people')->insertGetId([ |
||||
88 | // 'email'=>$this->email, |
||||
89 | // 'name' => $this->name, |
||||
90 | // ]); |
||||
91 | // // g$tenant = Tenant::find('->initialize($tenant);et user_group_id |
||||
92 | // $tenants = Tenant::find($this->tenant->id); |
||||
93 | |||||
94 | // $tenant = tenancy()->initialize($tenants); |
||||
95 | // $person = $tenants->run(function () { |
||||
96 | // Person::create([ |
||||
97 | // 'email'=>$this->email, |
||||
98 | // 'name' => $this->name, |
||||
99 | |||||
100 | // ]); |
||||
101 | // }); |
||||
102 | // $user_group = 1; |
||||
103 | |||||
104 | // get role_id |
||||
105 | // $role = 1; |
||||
106 | // $tenants->run(function () { |
||||
107 | // User::create([ |
||||
108 | // 'email' => $this->email, |
||||
109 | // 'password' => Hash::make($this->password), |
||||
110 | // 'person_id' => $person, |
||||
111 | // 'group_id' => $user_group, |
||||
112 | // 'role_id' => $role, |
||||
113 | // 'is_active' => 1, |
||||
114 | |||||
115 | // ]); |
||||
116 | // }); |
||||
117 | |||||
118 | /** $person = DB::connection(Connections::Tenant)->table('users')->insert([ |
||||
119 | * 'email' => $this->email, |
||||
120 | * 'password' => Hash::make($this->password), |
||||
121 | * 'person_id' => $person, |
||||
122 | * 'group_id' => $user_group, |
||||
123 | * 'role_id' => $role, |
||||
124 | * 'is_active' => 1, |
||||
125 | * ]);. |
||||
126 | */ |
||||
127 | } |
||||
128 | } |
||||
129 |