added plan images to factory plan
BIN
database/assets/images/plans/1.jpg
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
database/assets/images/plans/10.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
database/assets/images/plans/2.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
database/assets/images/plans/3.jpg
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
database/assets/images/plans/4.jpg
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
database/assets/images/plans/5.jpg
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
database/assets/images/plans/6.jpg
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
database/assets/images/plans/7.jpg
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
database/assets/images/plans/8.jpg
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
database/assets/images/plans/9.jpg
Normal file
|
After Width: | Height: | Size: 20 KiB |
@@ -4,8 +4,8 @@ namespace Database\Factories;
|
||||
|
||||
use FakerRestaurant\Provider\en_US\Restaurant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\File;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Plan>
|
||||
@@ -19,7 +19,6 @@ class PlanFactory extends Factory
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
$this->faker->addProvider(new Restaurant($faker));
|
||||
|
||||
@@ -41,7 +40,6 @@ class PlanFactory extends Factory
|
||||
'description' => $this->faker->text(),
|
||||
];
|
||||
|
||||
|
||||
$packetsOptions2 = [
|
||||
'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()],
|
||||
'price' => $this->faker->randomNumber(),
|
||||
@@ -49,7 +47,6 @@ class PlanFactory extends Factory
|
||||
'description' => $this->faker->text(),
|
||||
];
|
||||
|
||||
|
||||
$packetsOptions3 = [
|
||||
'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()],
|
||||
'price' => $this->faker->randomNumber(),
|
||||
@@ -57,17 +54,11 @@ class PlanFactory extends Factory
|
||||
'description' => $this->faker->text(),
|
||||
];
|
||||
|
||||
Storage::fake('plans');
|
||||
$file = UploadedFile::fake()->image('plan.png');
|
||||
$fileLocalPath = $file->store('plans', 'public');
|
||||
|
||||
return [
|
||||
'name' => $this->faker->foodName(),
|
||||
// 'image' => UploadedFile::fake()->image('plans/Photo_C.png'),
|
||||
'image' => $fileLocalPath,
|
||||
'image' => $this->generateImageFile(),
|
||||
'duration' => $this->faker->randomElement([7, 14, 21]),
|
||||
'state' => $this->faker->randomElement(['active', 'draft', 'unactive']),
|
||||
//'type' => $this->faker->randomElement([$typeBody, $wrongTypeBody]),
|
||||
'type' => $typeBody,
|
||||
'details' => $this->faker->text(),
|
||||
'packets_count' => $active ? 3 : 1,
|
||||
@@ -76,4 +67,16 @@ class PlanFactory extends Factory
|
||||
'packet3_options' => $active ? $packetsOptions3 : '',
|
||||
];
|
||||
}
|
||||
|
||||
private function generateImageFile(string $name = 'plans')
|
||||
{
|
||||
$images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'];
|
||||
Storage::fake($name);
|
||||
$imageFileKey = $this->faker->numberBetween(0, 9);
|
||||
$imageFilePath = 'database/assets/images/plans/' . $images[$imageFileKey];
|
||||
$file = new File($imageFilePath);
|
||||
$fileLocalPath = Storage::putFile($name, $file, 'public');
|
||||
|
||||
return $fileLocalPath;
|
||||
}
|
||||
}
|
||||
|
||||