use App\Abstracts\Factory;
use App\Models\Banking\Account as Model;
class Account extends Factory
{
protected $model = Model::class;
public function definition()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'number' => (string) $this->faker->iban(),
'currency_code' => $this->company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
'opening_balance' => '0',
'bank_name' => $this->faker->text(15),
'bank_phone' => $this->faker->phoneNumber,
'bank_address' => $this->faker->address,
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
public function enabled()
{
return $this->state([
'enabled' => 1,
]);
}
}
use App\Models\Banking\Account;
use Illuminate\Database\Seeder;
class SampleData extends Seeder
{
public function run()
{
Model::reguard();
$this->command->info('Creating sample data...');
$bar = $this->command->getOutput()->createProgressBar(7);
$bar->setFormat('verbose');
$bar->start();
$count = (int) $this->command->option('count');
$small_count = ($count <= 10) ? $count : 10;
Account::factory()->count($small_count)->create();
$bar->advance();
$this->command->info('');
$this->command->info('Sample data created.');
Model::unguard();
}
}
Additional resources on factories:
-
Povilas Korop | www.youtube.com
Published on
-
Article
shani singh | dev.to
Published on