added plan images to factory plan

This commit is contained in:
2023-12-27 12:49:27 +03:00
parent d9d64e2feb
commit 1fe0d06322
11 changed files with 14 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -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;
}
}