|
|
<?php
namespace Database\Factories;
use App\Image\ImageProcessor; use App\Models\Collection; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str;
/** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\File> */ class FileFactory extends Factory { use BaseFactory;
private $uuid = null;
/** * Define the model's default state. * * @return array<string, mixed> */ public function definition() { $this->uuid = app()->uuid; return [ "uuid" => $this->uuid, "original_name" => fake()->name(), "ext" => ['jpg', 'jpeg', 'png', 'webp'][rand(0, 3)], "mimetype" => 'image', "width" => rand(300, 2000), "height" => rand(300, 2000), "file_size" => rand(300, 2000), "sort" => rand(0, 23), "server_path" => '/' . date('y') . '/' . date('m') . '/', "alts" => [ 'hello wroldswdfouiwref iuwrhgf ow rgfaw ghfawej', 'jhsf asduyfsadf sadf safsuf isfjsdfsudifsduiyf sdiuf sd' ], "description" => 'ajsfoisahjfoaspf asduf safsafjsh lh', "user_id" => 1, "ip" => "127.0. 0.1", // "collection_id" => $collection->id,
"published_at" => "2022-07-27 09:17:59", ]; }
public function dependencyProvider($dependencyAttributes = []) {
if (array_key_exists('withImage', $dependencyAttributes)) { if ($dependencyAttributes['withImage'] == true) { unset($dependencyAttributes['withImage']); $collection = Collection::factory()->createQuietly($dependencyAttributes); $imageProcessor = new ImageProcessor; $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path('/' . date('y') . '/' . date('m') . '/' . $this->uuid . '.' . $collection->ext)); }
} else { $collection = Collection::factory()->createQuietly($dependencyAttributes); }
return [ 'collection_id' => $collection ]; } }
|