![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/syn.corals.io/Corals/modules/Syndicate/database/factories/ |
<?php namespace Corals\Modules\Syndicate\database\factories; use Corals\Modules\Syndicate\Models\Fee; use Corals\Modules\Syndicate\Models\FeeTransaction; use Corals\Modules\Syndicate\Models\Pharmacist; use Corals\Modules\Utility\Facades\ListOfValue\ListOfValues; use Illuminate\Database\Eloquent\Factories\Factory; class FeeFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = Fee::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'user_id' => function () { return Pharmacist::query()->inRandomOrder()->first()->id; }, 'type_code' => $this->faker->randomKey(ListOfValues::get('Syndicate::transaction_type', false, 'active', true)), 'year' => $this->faker->year('now'), 'details' => $this->faker->text(200), 'due' => $this->faker->randomFloat(1, 1, 20000), 'paid' => $this->faker->randomFloat(1, 1, 20000), ]; } public function configure() { $count = array_rand([0, 1, 2]); if ($count != 0) { return $this->afterMaking(function (Fee $fee) { })->afterCreating(function (Fee $fee) use ($count) { FeeTransaction::factory()->count($count)->make() ->each(function (FeeTransaction $transaction) use ($fee) { $transaction->setAttribute('user_id', $fee->user_id); $fee->feeTransactions()->save($transaction); }); }); } else { return $this->afterMaking(function (Fee $fee) { })->afterCreating(function (Fee $fee) { }); } } }