2023-06-11 12:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Newsletter\Http\Controllers;
|
|
|
|
|
|
|
|
use Newsletter;
|
2023-12-03 14:07:47 +00:00
|
|
|
use Illuminate\Http\Response;
|
2023-06-11 12:14:03 +00:00
|
|
|
use Modules\Newsletter\Http\Requests\StoreSubscriberRequest;
|
|
|
|
|
|
|
|
class SubscriberController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2023-12-03 14:07:47 +00:00
|
|
|
* @return Response
|
2023-06-11 12:14:03 +00:00
|
|
|
*/
|
|
|
|
public function store(StoreSubscriberRequest $request)
|
|
|
|
{
|
|
|
|
Newsletter::subscribeOrUpdate($request->email);
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!Newsletter::lastActionSucceeded()) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return response()->json([
|
|
|
|
'message' => str_after(Newsletter::getLastError(), '400: '),
|
|
|
|
], 403);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|