Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created BackEnd for Contact #58

Merged
merged 2 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/Http/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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']);
}
}
}
11 changes: 11 additions & 0 deletions app/Models/Giveaway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Giveaway extends Model
{
use HasFactory;
}
11 changes: 11 additions & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Message extends Model
{
use HasFactory;
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@

Route::post('/getCategory', [APIController::class, 'getCategory'])->name('getCategory');
Route::post('/subscribeuser',[APIController::class, 'subscribeuser'] );
Route::post('/contact',[APIController::class, 'contact'] );