diff --git a/app/Http/Controllers/APIController.php b/app/Http/Controllers/APIController.php index 10ab261..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; @@ -19,6 +21,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 { @@ -32,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'] );