diff --git a/app/Http/Controllers/API/EventController.php b/app/Http/Controllers/API/EventController.php index 42dde01..6ea8738 100644 --- a/app/Http/Controllers/API/EventController.php +++ b/app/Http/Controllers/API/EventController.php @@ -21,6 +21,12 @@ public function index(Calendar $calendar) ->events() ->get(); + // Set the full path on the image attribute + $events->transform(function ($event) { + $event->image = asset('storage/banners/' . $event->image); + return $event; + }); + return response()->json(['data' => $events->values()], 200); } @@ -67,7 +73,7 @@ public function store(Request $request) if (!Storage::disk('public')->exists($storedPath)) { return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput(); } - + } $event = Event::create([ diff --git a/tests/Feature/Misc/APITest.php b/tests/Feature/Misc/APITest.php index e75f780..7699cc0 100644 --- a/tests/Feature/Misc/APITest.php +++ b/tests/Feature/Misc/APITest.php @@ -7,6 +7,7 @@ use App\Models\Event; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Http\UploadedFile; use Tests\TestCase; class APITest extends TestCase @@ -61,7 +62,10 @@ public function test_events_can_be_recieved_from_the_api() $api = ApiKey::factory()->create(); // Create test event - $event = Event::factory()->create(); + $image = UploadedFile::fake()->image('test_image.jpg', $width = 1600, $height = 900); + $event = Event::factory()->create([ + 'image' => $image, + ]); // Send a GET request to the API endpoint with the bearer token in the headers $response = $this->withHeaders([