Skip to content

Commit b518603

Browse files
committed
Removes external dependency for Blog Seeder images
1 parent 9a12972 commit b518603

File tree

53 files changed

+97
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+97
-84
lines changed

src/Console/InstallCommand.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function handle(): void
1818
$this->copyBlogModuleDirectory();
1919
$this->copyResourcesFiles();
2020
$this->copyResourcesSiteFiles();
21+
$this->copyBlogSeederImages();
2122
$this->copyResourcesComponentsFiles();
2223
$this->copyTranslationFile();
2324

@@ -44,31 +45,39 @@ private function copyBlogModuleDirectory(): void
4445
{
4546
$this->info('Copying Blog Module directory...');
4647
(new Filesystem)->ensureDirectoryExists(base_path('modules'));
47-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/modules/Blog', base_path('modules/Blog'));
48+
(new Filesystem)->copyDirectory(__DIR__ . '/../../stubs/modules/Blog', base_path('modules/Blog'));
4849
$this->info('Blog Module directory copied successfully.');
4950
}
5051

5152
private function copyResourcesComponentsFiles(): void
5253
{
5354
$this->info('Copying Blog Module components...');
5455
(new Filesystem)->ensureDirectoryExists(resource_path('js/Components/Modules/Blog'));
55-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/js/Components/Modules/Blog', resource_path('js/Components/Modules/Blog'));
56+
(new Filesystem)->copyDirectory(__DIR__ . '/../../stubs/resources/js/Components/Modules/Blog', resource_path('js/Components/Modules/Blog'));
5657
$this->info('Blog Module components copied successfully.');
5758
}
5859

60+
private function copyBlogSeederImages(): void
61+
{
62+
$this->info('Copying Blog Seeder images...');
63+
(new Filesystem)->ensureDirectoryExists(resource_path('images/blog'));
64+
(new Filesystem)->copyDirectory(__DIR__ . '/../../stubs/resources/images/blog', resource_path('images/blog'));
65+
$this->info('Blog Module Seeder images copied successfully.');
66+
}
67+
5968
private function copyResourcesFiles(): void
6069
{
6170
$this->info('Copying Blog Module resources...');
6271
(new Filesystem)->ensureDirectoryExists(resource_path('js/Pages'));
63-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources/js/Pages', resource_path('js/Pages'));
72+
(new Filesystem)->copyDirectory(__DIR__ . '/../../stubs/resources/js/Pages', resource_path('js/Pages'));
6473
$this->info('Blog Module resources copied successfully.');
6574
}
6675

6776
private function copyResourcesSiteFiles(): void
6877
{
6978
$this->info('Copying Blog Module resources-site...');
7079
(new Filesystem)->ensureDirectoryExists(base_path('resources-site'));
71-
(new Filesystem)->copyDirectory(__DIR__.'/../../stubs/resources-site', base_path('resources-site'));
80+
(new Filesystem)->copyDirectory(__DIR__ . '/../../stubs/resources-site', base_path('resources-site'));
7281
$this->info('Blog Module resources-site copied successfully.');
7382
}
7483

@@ -78,7 +87,7 @@ private function copyTranslationFile(): void
7887

7988
if (! file_exists($paginationEnglish)) {
8089
(new Filesystem)->ensureDirectoryExists(base_path('lang/en'));
81-
copy(__DIR__.'/../../stubs/lang/en/pagination.php', base_path('lang/en/pagination.php'));
90+
copy(__DIR__ . '/../../stubs/lang/en/pagination.php', base_path('lang/en/pagination.php'));
8291
}
8392
}
8493
}

stubs/modules/Blog/Database/Factories/BlogAuthorFactory.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
namespace Modules\Blog\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Illuminate\Support\Facades\Storage;
7-
use Illuminate\Support\Str;
86
use Modules\Blog\Models\Author;
9-
use Throwable;
107

118
class BlogAuthorFactory extends Factory
129
{
@@ -18,26 +15,11 @@ public function definition(): array
1815
'name' => $this->faker->name(),
1916
'email' => $this->faker->unique()->safeEmail(),
2017
'bio' => $this->faker->realTextBetween(),
21-
'image' => $this->createImage(),
18+
'image' => $this->faker->imageUrl(),
2219
'github_handle' => $this->faker->userName(),
2320
'twitter_handle' => $this->faker->userName(),
2421
'created_at' => $this->faker->dateTimeBetween('-1 year', '-3 month'),
2522
'updated_at' => $this->faker->dateTimeBetween('-2 month', 'now'),
2623
];
2724
}
28-
29-
private function createImage(): string
30-
{
31-
try {
32-
$image = file_get_contents('https://source.unsplash.com/random/240x240?adult');
33-
} catch (Throwable $exception) {
34-
return 'Error fetching image: '.$exception->getMessage();
35-
}
36-
37-
$fileName = Str::uuid().'.jpg';
38-
39-
Storage::disk('public')->put("blog/$fileName", $image);
40-
41-
return $fileName;
42-
}
4325
}

stubs/modules/Blog/Database/Factories/BlogCategoryFactory.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Modules\Blog\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Illuminate\Support\Facades\Storage;
76
use Illuminate\Support\Str;
87
use Modules\Blog\Models\Category;
9-
use Throwable;
108

119
class BlogCategoryFactory extends Factory
1210
{
@@ -19,7 +17,7 @@ public function definition(): array
1917
return [
2018
'name' => $name,
2119
'description' => $this->faker->realText(),
22-
'image' => $this->createImage(),
20+
'image' => $this->faker->imageUrl(),
2321
'is_visible' => $this->faker->boolean(),
2422
'slug' => Str::slug($name),
2523
'meta_tag_title' => Str::limit($name, 60, ''),
@@ -28,19 +26,4 @@ public function definition(): array
2826
'updated_at' => $this->faker->dateTimeBetween('-5 month', 'now'),
2927
];
3028
}
31-
32-
private function createImage(): string
33-
{
34-
try {
35-
$image = file_get_contents('https://source.unsplash.com/random/320x75?nature');
36-
} catch (Throwable $exception) {
37-
return 'Error fetching image: '.$exception->getMessage();
38-
}
39-
40-
$fileName = Str::uuid().'.jpg';
41-
42-
Storage::disk('public')->put("blog/$fileName", $image);
43-
44-
return $fileName;
45-
}
4629
}

stubs/modules/Blog/Database/Factories/BlogPostFactory.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Modules\Blog\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Illuminate\Support\Facades\Storage;
76
use Illuminate\Support\Str;
87
use Modules\Blog\Models\Post;
9-
use Throwable;
108

119
class BlogPostFactory extends Factory
1210
{
@@ -20,27 +18,12 @@ public function definition(): array
2018
'title' => $title,
2119
'slug' => Str::slug($title),
2220
'content' => $this->faker->realText(),
23-
'image' => $this->createImage(),
21+
'image' => $this->faker->imageUrl(),
2422
'meta_tag_title' => Str::limit($title, 60, ''),
2523
'meta_tag_description' => Str::limit($title, 160, ''),
2624
'published_at' => $this->faker->dateTimeBetween('-6 month', '+3 month'),
2725
'created_at' => $this->faker->dateTimeBetween('-1 year', '-6 month'),
2826
'updated_at' => $this->faker->dateTimeBetween('-5 month', 'now'),
2927
];
3028
}
31-
32-
private function createImage(): string
33-
{
34-
try {
35-
$image = file_get_contents('https://source.unsplash.com/random/240x240?nature');
36-
} catch (Throwable $exception) {
37-
return 'Error fetching image: '.$exception->getMessage();
38-
}
39-
40-
$fileName = Str::uuid().'.jpg';
41-
42-
Storage::disk('public')->put("blog/$fileName", $image);
43-
44-
return $fileName;
45-
}
4629
}

stubs/modules/Blog/Database/Seeders/BlogSeeder.php

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,113 @@
22

33
namespace Modules\Blog\Database\Seeders;
44

5+
use Illuminate\Database\Eloquent\Factories\Sequence;
56
use Illuminate\Database\Seeder;
7+
use Illuminate\Filesystem\Filesystem;
68
use Illuminate\Support\Facades\Schema;
79
use Illuminate\Support\Facades\Storage;
810
use Modules\Blog\Models\Author;
911
use Modules\Blog\Models\Category;
1012
use Modules\Blog\Models\Post;
11-
1213
use function Laravel\Prompts\info;
13-
use function Laravel\Prompts\progress;
1414

1515
class BlogSeeder extends Seeder
1616
{
17+
18+
//These images are available at: resources/images/blog . Just copy them to storage/app/public/blog as mentioned in the README.md
19+
20+
private $blogCategoriesImages = [
21+
'57b76f29-dd7d-4018-b172-a06e6ef4a4cf.jpg',
22+
'f0d5596c-d23a-4db7-97a5-9a298b924994.jpg',
23+
'44a928b1-5148-4940-af48-2792f1151272.jpg',
24+
'5febe62d-d9bd-4054-b5a1-83b796ca9d14.jpg',
25+
'9ab99b32-1f04-495e-b5a2-5fa789dedd18.jpg',
26+
'24521518-b796-445f-8e9a-59233d8d78fa.jpg',
27+
'0d2dc407-6b6f-4022-9565-1ecec79daf52.jpg',
28+
'153cfa68-8ca8-4712-a1c1-1bd969796ef9.jpg',
29+
'3d7da554-1a6c-44f6-9f9f-2a6947446a65.jpg',
30+
'cd2dc303-24c8-41b3-b09e-83205a647d8f.jpg',
31+
'edb880ab-4e13-4594-b6d1-fa4125a00100.jpg',
32+
'034cb604-d3d0-448b-92f1-6a255fb4653d.jpg',
33+
];
34+
35+
private $blogAuthorsImages = [
36+
'a98ea6d4-9f8b-4897-9c63-bdafc1acd602.jpg',
37+
'77aa4a7a-de06-4ae6-8a1d-42322f532c53.jpg',
38+
'da4bc233-b12b-4548-904c-b3cf70711607.jpg',
39+
'b51306e7-f8f8-49b3-9083-e3fffccad1b4.jpg',
40+
'8c183760-1de3-4f6a-bef6-7241e7ebbb2f.jpg',
41+
'dc44c3b1-6de3-4c47-80bb-e28de18f314b.jpg',
42+
'850e4903-66fe-4feb-a218-64058bb84a6a.jpg',
43+
'cf45d6f9-0ff0-41ae-966b-a7fa50f08e33.jpg',
44+
'fe15a944-36e4-4c0b-a634-f9e6c00df101.jpg',
45+
'15dcfc3d-f8f4-470e-9477-72322e399731.jpg',
46+
'735aa22c-6aa0-4ced-9552-5494f0da4e5e.jpg',
47+
'bac12f21-8eaa-437e-bf0c-2ae84ca2b02a.jpg',
48+
];
49+
50+
private $blogPostsImages = [
51+
'faa02464-6d3e-49b9-a45c-de303c91f3d5.jpg',
52+
'49814997-b619-4281-842f-8729f2ec151c.jpg',
53+
'e9d82a31-b7a2-46d8-9da4-48f51f4207aa.jpg',
54+
'e42eefc0-7f34-4645-ba21-d9c931daf08f.jpg',
55+
'f5e456c2-de4b-48c2-9554-54b8b8e7bfbc.jpg',
56+
'2a7f2576-82a1-4f28-9f38-5a9cc216ba16.jpg',
57+
'94ab2a3f-2300-4754-b458-2cc36cceac05.jpg',
58+
'e6ebdade-56ec-4d59-9da2-cf479b7d8c46.jpg',
59+
'f6d0c648-5d59-4b96-9c44-ebdc0ba3ee38.jpg',
60+
'3fe0425a-96a4-49b5-bcde-adf75caa626d.jpg',
61+
'500862ad-b078-4306-9348-39edf65f6d05.jpg',
62+
'2348a092-55d0-4b6d-b43d-3b34280dbed9.jpg',
63+
'57135dbe-7d31-4380-85cd-b78179ca2400.jpg',
64+
'75fca485-2ea3-47d0-b609-9c8bd58d3438.jpg',
65+
'4c798d2c-c4a6-4293-b052-98a048914215.jpg',
66+
'b8cac8c5-c3d2-4a65-8ebb-1b74059fe309.jpg',
67+
'952536c8-e74c-4089-bce4-3cc3b474a2d2.jpg',
68+
'5f4ecece-6275-41b9-bd64-0e6f904a5df7.jpg',
69+
'463c0606-1382-49b3-8ba5-3a3b91c4ff09.jpg',
70+
'd27f5f87-f8dd-47df-8b2e-5086a5ba66c1.jpg',
71+
'5a888786-090c-40f1-85e0-f86895311eeb.jpg',
72+
'68255060-d85e-4081-a025-931789e6aa1d.jpg',
73+
'4e8d6a91-e0ef-48aa-86cd-8d18699407c3.jpg',
74+
'548857a2-c1b5-490e-b3a2-20a28ba98e0f.jpg',
75+
];
76+
1777
public function run(): void
1878
{
19-
Storage::deleteDirectory('public/blog');
79+
$this->setupBlogImages();
2080

2181
Schema::disableForeignKeyConstraints();
2282

2383
info('Creating blog categories...');
24-
$this->seedWithProgress(
25-
label: 'Categories creation status',
26-
steps: 12,
27-
callback: fn () => Category::factory()->create(),
28-
);
84+
Category::factory()->count(12)
85+
->sequence(fn(Sequence $sequence) => ['image' => $this->blogCategoriesImages[$sequence->index]])
86+
->create();
2987
info('Blog categories created.');
3088

3189
info('Creating blog authors...');
32-
$this->seedWithProgress(
33-
label: 'Authors creation status',
34-
steps: 12,
35-
callback: fn () => Author::factory()->create(),
36-
);
90+
Author::factory()->count(12)
91+
->sequence(fn(Sequence $sequence) => ['image' => $this->blogAuthorsImages[$sequence->index]])
92+
->create();
3793
info('Blog authors created.');
3894

3995
info('Creating blog posts...');
40-
$this->seedWithProgress(
41-
label: 'Posts creation status',
42-
steps: 24,
43-
callback: fn () => Post::factory()->create(),
44-
);
96+
Post::factory()->count(24)
97+
->sequence(fn(Sequence $sequence) => ['image' => $this->blogPostsImages[$sequence->index]])
98+
->create();
4599
info('Blog posts created.');
46100

47101
Schema::enableForeignKeyConstraints();
48102
}
49103

50-
private function seedWithProgress(string $label, int $steps, callable $callback): void
104+
private function setupBlogImages(): void
51105
{
52-
progress(
53-
label: $label,
54-
steps: $steps,
55-
callback: $callback,
56-
);
106+
Storage::deleteDirectory('public/blog');
107+
info('Copying blog images...');
108+
109+
(new Filesystem)->ensureDirectoryExists(base_path('storage/app/public/blog'));
110+
(new Filesystem)->copyDirectory(base_path('resources/images/blog'), base_path('storage/app/public/blog'));
111+
112+
info('The blog images were copied.');
57113
}
58114
}

0 commit comments

Comments
 (0)