2018-10-15 07:00:48 +02:00
|
|
|
<?php
|
|
|
|
|
2019-01-15 23:00:25 +01:00
|
|
|
use App\DataMapper\DefaultSettings;
|
2018-10-15 07:00:48 +02:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2018-10-24 12:24:09 +02:00
|
|
|
use App\Models\ClientContact;
|
2018-10-15 07:00:48 +02:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\UserAccount;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class UsersTableSeeder extends Seeder
|
|
|
|
{
|
2018-10-29 04:16:17 +01:00
|
|
|
use \App\Utils\Traits\MakesHash;
|
2018-10-15 07:00:48 +02:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
$this->command->info('Running UsersTableSeeder');
|
2018-10-15 07:00:48 +02:00
|
|
|
|
|
|
|
Eloquent::unguard();
|
|
|
|
|
|
|
|
$faker = Faker\Factory::create();
|
|
|
|
|
2018-10-24 12:24:09 +02:00
|
|
|
$account = factory(\App\Models\Account::class)->create();
|
|
|
|
$company = factory(\App\Models\Company::class)->create([
|
|
|
|
'account_id' => $account->id,
|
2019-07-12 07:03:30 +02:00
|
|
|
'domain' => 'ninja.test',
|
2018-10-15 07:00:48 +02:00
|
|
|
]);
|
|
|
|
|
2018-10-24 12:24:09 +02:00
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
$user = factory(\App\Models\User::class)->create([
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
2018-10-15 07:00:48 +02:00
|
|
|
]);
|
|
|
|
|
2019-01-07 12:30:28 +01:00
|
|
|
|
|
|
|
$userPermissions = collect([
|
|
|
|
'view_invoice',
|
|
|
|
'view_client',
|
|
|
|
'edit_client',
|
|
|
|
'edit_invoice',
|
|
|
|
'create_invoice',
|
|
|
|
'create_client'
|
|
|
|
]);
|
|
|
|
|
2019-01-15 23:00:25 +01:00
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
2019-01-07 12:30:28 +01:00
|
|
|
'permissions' => $userPermissions->toJson(),
|
2020-02-26 04:26:07 +01:00
|
|
|
'settings' => null,
|
2018-11-02 11:54:46 +01:00
|
|
|
'is_locked' => 0,
|
|
|
|
]);
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
$client = factory(\App\Models\Client::class)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id
|
2018-10-15 07:00:48 +02:00
|
|
|
]);
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
|
2018-10-24 12:24:09 +02:00
|
|
|
ClientContact::create([
|
2018-10-15 07:00:48 +02:00
|
|
|
'first_name' => $faker->firstName,
|
|
|
|
'last_name' => $faker->lastName,
|
2018-10-24 12:24:09 +02:00
|
|
|
'email' => config('ninja.testvars.clientname'),
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'password' => Hash::make(config('ninja.testvars.password')),
|
2018-10-21 00:26:21 +02:00
|
|
|
'email_verified_at' => now(),
|
2018-10-15 07:00:48 +02:00
|
|
|
'client_id' =>$client->id,
|
|
|
|
]);
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
|
2019-03-27 07:22:27 +01:00
|
|
|
factory(\App\Models\Client::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
2018-10-29 04:16:17 +01:00
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,10)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-10-15 07:00:48 +02:00
|
|
|
}
|
|
|
|
}
|