Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

Commit b92a0f3

Browse files
author
José Postiga
committed
fix(Links): add missing file storage support for cover images
1 parent 4ed1da1 commit b92a0f3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

domains/Links/Controllers/LinksStoreController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __invoke(LinkStoreRequest $request): Response
2323
'description' => $request->input('description'),
2424
'author_name' => $request->input('author_name'),
2525
'author_email' => $request->input('author_email'),
26-
'cover_image' => $request->file('cover_image')->getClientOriginalName(),
26+
'cover_image' => $request->file('cover_image')->store('cover_images'),
2727
]);
2828

2929
$link->tags()->attach($request->input('tags.*.id'));

domains/Links/Database/Factories/LinkFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
use Domains\Links\Models\Link;
44
use Illuminate\Database\Eloquent\Factory;
5+
use Illuminate\Http\UploadedFile;
56
use Illuminate\Support\Carbon;
67

7-
/** @var $factory Factory */
8+
/** @var Factory $factory */
89
$factory->define(Link::class, static fn (\Faker\Generator $faker) => [
910
'link' => $faker->url,
1011
'description' => $faker->paragraph,
11-
'cover_image' => $faker->image(),
12+
'cover_image' => 'cover_images/' . UploadedFile::fake()->image('cover_image')->getFilename(),
1213
'author_name' => $faker->name,
1314
'author_email' => $faker->safeEmail,
1415
'created_at' => Carbon::now(),

domains/Links/Tests/Feature/LinksStoreTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Foundation\Testing\RefreshDatabase;
77
use Illuminate\Foundation\Testing\WithFaker;
88
use Illuminate\Http\UploadedFile;
9+
use Illuminate\Support\Facades\Storage;
910
use Tests\TestCase;
1011

1112
class LinksStoreTest extends TestCase
@@ -25,6 +26,8 @@ protected function setUp(): void
2526
/** @test */
2627
public function it_stores_resources(): void
2728
{
29+
Storage::fake();
30+
2831
$payload = [
2932
'link' => $this->faker->url,
3033
'description' => $this->faker->paragraph,
@@ -44,7 +47,7 @@ public function it_stores_resources(): void
4447
'description' => $payload['description'],
4548
'author_name' => $payload['author_name'],
4649
'author_email' => $payload['author_email'],
47-
'cover_image' => 'cover_image.jpg',
50+
'cover_image' => 'cover_images/' . $payload['cover_image']->hashName(),
4851
'approved_at' => null,
4952
]);
5053

@@ -54,6 +57,8 @@ public function it_stores_resources(): void
5457
'tag_id' => $this->tag->id,
5558
]
5659
);
60+
61+
Storage::assertExists('cover_images/' . $payload['cover_image']->hashName());
5762
}
5863

5964
/** @test */

0 commit comments

Comments
 (0)