1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/database/seeders/UsersTableSeeder.php

105 lines
3.0 KiB
PHP
Raw Normal View History

2020-10-01 13:34:05 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-10-01 13:34:05 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
2020-10-01 13:34:05 +02:00
*/
2020-10-01 13:34:05 +02:00
namespace Database\Seeders;
use App\DataMapper\CompanySettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
use App\Models\Company;
use Illuminate\Support\Facades\Hash;
2020-10-01 13:34:05 +02:00
class UsersTableSeeder extends Seeder
{
use \App\Utils\Traits\MakesHash;
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->command->info('Running UsersTableSeeder');
Model::unguard();
$faker = \Faker\Factory::create();
$account = Account::factory()->create();
$company = Company::factory()->create([
'account_id' => $account->id,
'domain' => 'ninja.test',
]);
$account->default_company_id = $company->id;
$account->save();
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
]);
$userPermissions = collect([
'view_invoice',
'view_client',
'edit_client',
'edit_invoice',
'create_invoice',
'create_client',
]);
2020-10-01 13:34:05 +02:00
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'notifications' => CompanySettings::notificationDefaults(),
'permissions' => $userPermissions->toJson(),
'settings' => null,
'is_locked' => 0,
]);
$client = Client::factory()->create([
'user_id' => $user->id,
'company_id' => $company->id,
]);
ClientContact::create([
'first_name' => $faker->firstName(),
'last_name' => $faker->lastName(),
2020-10-01 13:34:05 +02:00
'email' => config('ninja.testvars.clientname'),
'company_id' => $company->id,
'password' => Hash::make(config('ninja.testvars.password')),
'email_verified_at' => now(),
'client_id' =>$client->id,
]);
Client::factory()->count(20)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $c->id,
'company_id' => $company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(10)->create([
'user_id' => $user->id,
'client_id' => $c->id,
'company_id' => $company->id,
]);
});
}
}