ResolutionFactory.php
1 <?php 2 3 namespace Database\Factories; 4 5 use App\Models\Dossier; 6 use App\Models\Resolution; 7 use App\Models\Revision; 8 use Illuminate\Database\Eloquent\Factories\Factory; 9 10 class ResolutionFactory extends Factory 11 { 12 /** 13 * The name of the factory's corresponding model. 14 * 15 * @var string 16 */ 17 protected $model = Resolution::class; 18 19 /** 20 * Define the model's default state. 21 * 22 * @return array 23 */ 24 public function definition() 25 { 26 $last_seq_code = Resolution::where('code_year', date('Y'))->orderByDesc('created_at')->first(); 27 if ($last_seq_code) { 28 $number = str_pad($last_seq_code->code_seq + 1, 4, '0', STR_PAD_LEFT); 29 } else { 30 $number = str_pad(1, 4, '0', STR_PAD_LEFT); 31 } 32 33 return [ 34 'code_year' => date('Y'), 35 'code_seq' => $number, 36 'dossier_id' => Dossier::all()->random()->id, 37 'infor_cert_id' => null, //Revision::all()->random()->id, 38 /* 'resolved_doc' => '', */ 39 'resolved_doc_id' => null, //Revision::all()->random()->id, 40 'approved' => $this->faker->boolean(), 41 'BOE_code' => $this->faker->word(), 42 'publication_date' => now(), 43 'certification_date' => now(), 44 'resolution_date' => now(), 45 ]; 46 } 47 }