You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace Database\Factories;
  3. use App\Image\ImageProcessor;
  4. use App\Models\Collection;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. use Illuminate\Support\Facades\App;
  7. use Illuminate\Support\Facades\Storage;
  8. use Illuminate\Support\Str;
  9. /**
  10. * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\File>
  11. */
  12. class FileFactory extends Factory
  13. {
  14. use BaseFactory;
  15. private $uuid = null;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition()
  22. {
  23. $this->uuid = app()->uuid;
  24. return [
  25. "uuid" => $this->uuid,
  26. "original_name" => fake()->name(),
  27. "ext" => ['jpg', 'jpeg', 'png', 'webp'][rand(0, 3)],
  28. "mimetype" => 'image',
  29. "width" => rand(300, 2000),
  30. "height" => rand(300, 2000),
  31. "file_size" => rand(300, 2000),
  32. "sort" => rand(0, 23),
  33. "server_path" => '/' . date('y') . '/' . date('m') . '/',
  34. "alts" => [
  35. 'hello wroldswdfouiwref iuwrhgf ow rgfaw ghfawej',
  36. 'jhsf asduyfsadf sadf safsuf isfjsdfsudifsduiyf sdiuf sd'
  37. ],
  38. "description" => 'ajsfoisahjfoaspf asduf safsafjsh lh',
  39. "user_id" => 1,
  40. "ip" => "127.0. 0.1",
  41. // "collection_id" => $collection->id,
  42. "published_at" => "2022-07-27 09:17:59",
  43. ];
  44. }
  45. public function dependencyProvider($dependencyAttributes = [])
  46. {
  47. if (array_key_exists('withImage', $dependencyAttributes)) {
  48. if ($dependencyAttributes['withImage'] == true) {
  49. unset($dependencyAttributes['withImage']);
  50. $collection = Collection::factory()->createQuietly($dependencyAttributes);
  51. $imageProcessor = new ImageProcessor;
  52. $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path('/' . date('y') . '/' . date('m') . '/' . $this->uuid . '.' . $collection->ext));
  53. }
  54. } else {
  55. $collection = Collection::factory()->createQuietly($dependencyAttributes);
  56. }
  57. return [
  58. 'collection_id' => $collection
  59. ];
  60. }
  61. }