43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Societe;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class SocieteFactory extends Factory
|
|
{
|
|
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Societe::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
$logo = new UploadedFile(
|
|
$this->faker->image(null, 450, 360, 'compagnies', true, true),
|
|
sprintf('logo-%d.png', rand(10000, 99999))
|
|
);
|
|
$companyName = $this->faker->unique()->company();
|
|
$colors = [];
|
|
$total = rand(1, 3);
|
|
for ($i = 0; $i < $total; $i++) {
|
|
$colors["color$i"] = $this->faker->safeHexColor();
|
|
}
|
|
|
|
return [
|
|
'name' => $companyName,
|
|
'logo' => Societe::saveLogo($logo, $companyName),
|
|
'colors' => json_encode($colors)
|
|
];
|
|
}
|
|
}
|