2018-11-02 11:54:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
2019-03-27 05:50:13 +01:00
|
|
|
use App\Models\CompanyToken;
|
2018-11-02 11:54:46 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\UserAccount;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class RandomDataSeeder extends Seeder
|
|
|
|
{
|
|
|
|
use \App\Utils\Traits\MakesHash;
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->command->info('Running RandomDataSeeder');
|
|
|
|
|
|
|
|
Eloquent::unguard();
|
|
|
|
|
|
|
|
$faker = Faker\Factory::create();
|
|
|
|
|
|
|
|
$account = factory(\App\Models\Account::class)->create();
|
|
|
|
$company = factory(\App\Models\Company::class)->create([
|
|
|
|
'account_id' => $account->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$user = factory(\App\Models\User::class)->create([
|
|
|
|
'email' => $faker->email,
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
|
|
|
]);
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
$company_token = CompanyToken::create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'name' => 'test token',
|
|
|
|
'token' => str_random(64),
|
|
|
|
]);
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$client = factory(\App\Models\Client::class)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
ClientContact::create([
|
|
|
|
'first_name' => $faker->firstName,
|
|
|
|
'last_name' => $faker->lastName,
|
|
|
|
'email' => $faker->email,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'password' => Hash::make(config('ninja.testvars.password')),
|
|
|
|
'email_verified_at' => now(),
|
|
|
|
'client_id' =>$client->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
factory(\App\Models\Client::class, 5)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
factory(\App\Models\ClientContact::class,1)->create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1
|
|
|
|
]);
|
|
|
|
|
2018-11-03 02:01:40 +01:00
|
|
|
factory(\App\Models\ClientContact::class,10)->create([
|
2018-11-02 11:54:46 +01:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id
|
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-04-03 02:09:22 +02:00
|
|
|
/** Product Factory */
|
|
|
|
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
|
|
|
|
|
2019-04-04 03:38:17 +02:00
|
|
|
/** Invoice Factory */
|
|
|
|
factory(\App\Models\Invoice::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|