-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
…php_laravel_web into feat/fetch-a-role-in-an-organisation-endpoint
- Loading branch information
Showing
20 changed files
with
772 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/Http/Controllers/Api/V1/NewsletterSubscriptionController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V1; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use App\Models\NewsletterSubscription; | ||
use Illuminate\Contracts\Validation\Factory as ValidationFactory; | ||
use Illuminate\Http\Response; | ||
use Exception; | ||
|
||
class NewsletterSubscriptionController extends Controller | ||
{ | ||
protected $validator; | ||
|
||
public function __construct(ValidationFactory $validator) | ||
{ | ||
$this->validator = $validator; | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validator = $this->validator->make($request->all(), [ | ||
'email' => 'required|email|unique:newsletter_subscriptions,email' | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return response()->json([ | ||
'success' => false, | ||
'message' => 'Validation failed.', | ||
'errors' => $validator->errors() | ||
], Response::HTTP_BAD_REQUEST); | ||
} | ||
|
||
try { | ||
$newsletter_subscription = NewsletterSubscription::create([ | ||
'email' => $request->email | ||
]); | ||
|
||
return response()->json([ | ||
'data' => $newsletter_subscription, | ||
'message' => 'Newsletter Subscribed Successfully', | ||
'status_code' => 201 | ||
], Response::HTTP_CREATED); | ||
} catch (Exception $exception) { | ||
return response()->json([ | ||
'message' => 'Internal Server Error', | ||
'status_code' => 500 | ||
], 500); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.