diff --git a/README.md b/README.md index f975232..00a6e70 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ # Laravel Email Viewer +[![Latest Version on Packagist](https://img.shields.io/packagist/v/axyr/laravel-email-viewer.svg?style=flat-square)](https://packagist.org/packages/axyr/laravel-email-viewer) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-permission/run-tests-L8.yml?branch=main&label=Tests)](https://github.com/axyr/laravel-email-viewer/actions?query=workflow%3ATests+branch%3Amain) ## Introduction diff --git a/routes/emailviewer.php b/routes/emailviewer.php index d5a5044..d18fa13 100644 --- a/routes/emailviewer.php +++ b/routes/emailviewer.php @@ -1,10 +1,15 @@ name($routeNamespace . '.index'); -Route::get($routeNamespace . '/{id}', [JsonEmailController::class, 'show'])->name($routeNamespace . '.show'); -Route::delete($routeNamespace . '/{id}', [JsonEmailController::class, 'destroy'])->name($routeNamespace . '.destroy'); +Route::get($routeNamespace . '/json', [JsonEmailController::class, 'index'])->name($routeNamespace . '.json.index'); +Route::get($routeNamespace . '/{id}/json', [JsonEmailController::class, 'show'])->name($routeNamespace . '.json.show'); +Route::delete($routeNamespace . '/{id}/json', [JsonEmailController::class, 'destroy'])->name($routeNamespace . '.json.destroy'); + +Route::get($routeNamespace, [BladeEmailController::class, 'index'])->name($routeNamespace . '.index'); +Route::get($routeNamespace . '/{id}', [BladeEmailController::class, 'show'])->name($routeNamespace . '.show'); +Route::delete($routeNamespace . '/{id}', [BladeEmailController::class, 'destroy'])->name($routeNamespace . '.destroy'); diff --git a/src/Http/Controllers/BladeEmailController.php b/src/Http/Controllers/BladeEmailController.php index 2b18fe5..f149bcd 100644 --- a/src/Http/Controllers/BladeEmailController.php +++ b/src/Http/Controllers/BladeEmailController.php @@ -26,7 +26,7 @@ public function show(string|int $id): View return view('email-viewer::show', compact('emails', 'email')); } - public function destroy(tring|int $id): RedirectResponse + public function destroy(string|int $id): RedirectResponse { Emails::delete($id); diff --git a/tests/Http/Controllers/JsonEmailControllerTest.php b/tests/Http/Controllers/JsonEmailControllerTest.php index 6e0c853..e332325 100644 --- a/tests/Http/Controllers/JsonEmailControllerTest.php +++ b/tests/Http/Controllers/JsonEmailControllerTest.php @@ -25,13 +25,14 @@ class JsonEmailControllerTest extends TestCase public function testListsPaginatedEmails(): void { config()->set('emailviewer.default_pagination', 3); + $routeNamespace = config('emailviewer.route-namespace'); for ($i = 0; $i < 6; $i++) { app(Repository::class)->create($this->emailContent . $i); } - $response = $this->getJson(route($routeNamespace . '.index')); + $response = $this->getJson(route($routeNamespace . '.json.index')); $this->assertCount(3, $response->json('data')); @@ -44,7 +45,7 @@ public function testShowsAnEmail(): void $email = app(Repository::class)->create($this->emailContent); - $response = $this->getJson(route($routeNamespace . '.show', [$email->id()])); + $response = $this->getJson(route($routeNamespace . '.json.show', [$email->id()])); $this->assertEquals($this->resourceKeys, array_keys($response->json('data'))); } @@ -55,7 +56,7 @@ public function testDeletesAnEmail(): void $email = app(Repository::class)->create($this->emailContent); - $response = $this->deleteJson(route($routeNamespace . '.destroy', [$email->id()])); + $response = $this->deleteJson(route($routeNamespace . '.json.destroy', [$email->id()])); $response->assertStatus(204);