From b53857dd033ad8564fea1918ccc1ac26b9c5a1bc Mon Sep 17 00:00:00 2001 From: meinhoonharsh Date: Mon, 6 Sep 2021 23:30:38 +0530 Subject: [PATCH 1/2] Improved API for subscribe --- app/Http/Controllers/APIController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/APIController.php b/app/Http/Controllers/APIController.php index 10ab261..7fac93d 100644 --- a/app/Http/Controllers/APIController.php +++ b/app/Http/Controllers/APIController.php @@ -19,6 +19,12 @@ function getCategory(Request $req){ return blog_subcategory::where('parent_category',$req->catId)->get(); } function subscribeuser(Request $req){ + // Check if user already subscribed + $subscriber = subscriber::where('email',$req->email)->first(); + if($subscriber){ + return response()->json(['status'=>'error','message'=>'You are already subscribed']); + } + $subscriber = new subscriber; $subscriber->email = $req->email; try { From 1fa54bef00e8f7b3932236a389723c14ba5daf02 Mon Sep 17 00:00:00 2001 From: meinhoonharsh Date: Fri, 10 Sep 2021 16:21:28 +0530 Subject: [PATCH 2/2] Created Model and API for Contact --- app/Http/Controllers/APIController.php | 17 +++++++++++++++++ app/Models/Giveaway.php | 11 +++++++++++ app/Models/Message.php | 11 +++++++++++ routes/api.php | 1 + 4 files changed, 40 insertions(+) create mode 100644 app/Models/Giveaway.php create mode 100644 app/Models/Message.php diff --git a/app/Http/Controllers/APIController.php b/app/Http/Controllers/APIController.php index 7fac93d..cf57f2b 100644 --- a/app/Http/Controllers/APIController.php +++ b/app/Http/Controllers/APIController.php @@ -10,6 +10,8 @@ use App\Models\report; use App\Models\blog_category; use App\Models\blog_subcategory; +use App\Models\Message; +use App\Models\Giveaway; use Auth; use Mail; @@ -38,4 +40,19 @@ function subscribeuser(Request $req){ } + + function contact(Request $req){ + $message = new Message; + $message->name = $req->name; + $message->email = $req->email; + $message->message = $req->message; + try { + $message->save(); + return response()->json(['status'=>'success','message'=>'Message sent successfully']); + } + catch (\Exception $e) { + $message = $e->getMessage(); + return response()->json(['status'=>'error','message'=>'Something went wrong']); + } + } } diff --git a/app/Models/Giveaway.php b/app/Models/Giveaway.php new file mode 100644 index 0000000..33038fd --- /dev/null +++ b/app/Models/Giveaway.php @@ -0,0 +1,11 @@ +name('getCategory'); Route::post('/subscribeuser',[APIController::class, 'subscribeuser'] ); +Route::post('/contact',[APIController::class, 'contact'] );