*/ class FileFactory extends Factory { use BaseFactory; private $uuid = null; /** * Define the model's default state. * * @return array */ 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 ]; } }