60 lines
2 KiB
PHP
60 lines
2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Coupon;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Coupon>
|
|
*/
|
|
class CouponFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Coupon::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
$coupon = new Coupon();
|
|
|
|
// Create a carbon instance date.
|
|
$start_diffusion_date = Carbon::parse(fake()->date());
|
|
|
|
// Add random days to start diffusion date.
|
|
$end_diffusion_date = Carbon::parse($start_diffusion_date)->addDays(fake()->numberBetween(30, 365));
|
|
|
|
// Add random days to end diddusion date.
|
|
$end_validity_date = Carbon::parse($end_diffusion_date)->addDays(fake()->numberBetween(1, 30));
|
|
|
|
// Get a brand in DB to have is name and id.
|
|
$random_brand = fake()->randomElement(DB::table('brands')->get());
|
|
|
|
return [
|
|
'name' => fake()->unique()->word(),
|
|
'process_code' => fake()->unique()->bothify('?????-#####'),
|
|
'amount' => fake()->randomFloat(1, 0.1, 3),
|
|
'valid_on' => $random_brand->name,
|
|
'validity_period' => fake()->numberBetween(1, 30),
|
|
'legal_notices' => fake()->text(100),
|
|
'limit_qty' => fake()->numberBetween(0, 2),
|
|
'limit_period' => fake()->numberBetween(0, 30),
|
|
'status' => fake()->boolean(75),
|
|
'can_be_used' => $coupon->checkIfCanBeUsed(),
|
|
'start_diffusion_date' => fake()->boolean(75) ? $start_diffusion_date : null,
|
|
'end_diffusion_date' => fake()->boolean(75) ? $end_diffusion_date : null,
|
|
'end_validity_date' => fake()->boolean(75) ? $end_validity_date : null,
|
|
'brand_id' => $random_brand->id
|
|
];
|
|
}
|
|
}
|