first commit
This commit is contained in:
159
app/Http/Controllers/Frontend/HomeController.php
Normal file
159
app/Http/Controllers/Frontend/HomeController.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Admin\program;
|
||||
use App\Models\Admin\country;
|
||||
use App\Models\Admin\faq;
|
||||
use App\Models\Admin\blog_category;
|
||||
use App\Models\Admin\blog;
|
||||
use App\Models\Admin\Testimonial;
|
||||
use App\Models\Frontend\news_letter;
|
||||
use App\Models\Frontend\user_rating;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use App\Models\Admin\latest_update;
|
||||
|
||||
//use League\CommonMark\Attributes\Country;
|
||||
|
||||
|
||||
class HomeController extends Controller {
|
||||
|
||||
|
||||
public function index() {
|
||||
$show_program = Program::where('is_active', 1)->get()->toArray();
|
||||
$user_rating = user_rating::all()->toArray();
|
||||
$show_countries = country::all()->toArray();
|
||||
$latestFaqs = FAQ::latest()->limit(5)->get();
|
||||
$blog_one = blog::latest()->limit(1)->get();
|
||||
$blog_three = blog::latest()->limit(3)->get();
|
||||
$blog_categ = blog_category::latest()->limit(2)->get()->toArray();
|
||||
$testimonial = Testimonial::with('country')->get()->toArray();
|
||||
$country_count = country::count();
|
||||
|
||||
return view('Frontend.Pages.Home.home')
|
||||
->with([
|
||||
'program' => $show_program,
|
||||
'country' => $show_countries,
|
||||
'faq' => $latestFaqs,
|
||||
'blog_singal' => $blog_one,
|
||||
'blog_muilti' => $blog_three,
|
||||
'blog_category' => $blog_categ,
|
||||
'test' => $testimonial,
|
||||
'user_rate' => $user_rating,
|
||||
'country_count' => $country_count,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function getCountryFlag($countryCode) {
|
||||
$flag = Country::getEmojiFlag($countryCode);
|
||||
return $flag;
|
||||
}
|
||||
|
||||
public function get_countries() {
|
||||
$show_countries = Country::all(['country_code', 'name'])->toArray();
|
||||
|
||||
$countryData = collect($show_countries)->map(function ($item) {
|
||||
return [
|
||||
'id' => $item['country_code'],
|
||||
'text' => $item['name']
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($countryData);
|
||||
}
|
||||
|
||||
public function home_get_programs(Request $request) {
|
||||
$country_code = $request->input('country_code');
|
||||
|
||||
$country = Country::where('country_code', $country_code)->first()->toArray();
|
||||
// dd($country_code,$query->toSql(), $query->getBindings());
|
||||
$countryId = $country['id'];
|
||||
|
||||
$programs = Program::where('country_xid', $countryId)
|
||||
->where('is_active', 1)
|
||||
->get(['id', 'program_title', 'thumbnail'])
|
||||
->toArray();
|
||||
// dd($programs);
|
||||
return response()->json([
|
||||
'programs' => $programs,
|
||||
]);
|
||||
}
|
||||
|
||||
// public function insert_newsletter(Request $request) {
|
||||
// $existingEmail = news_letter::where('email', $request->input('email_id'))->first();
|
||||
// if ($existingEmail) {
|
||||
// return response()->json(['success' => false, 'status' => 400, 'message' => 'Email already exists. Please choose a different email']);
|
||||
// }
|
||||
//
|
||||
// $add_newsletter_data = new news_letter;
|
||||
// $add_newsletter_data->first_name = $request->input('first_name');
|
||||
// $add_newsletter_data->email = $request->input('email');
|
||||
// $add_newsletter_data->save();
|
||||
//
|
||||
// return response()->json(['success' => true, 'status' => 200, 'message' => 'Newsletter added successfully']);
|
||||
//}
|
||||
|
||||
public function insert_newsletter(Request $request) {
|
||||
try {
|
||||
$existingEmail = news_letter::where('email', $request->input('email_id'))->first();
|
||||
if ($existingEmail) {
|
||||
return response()->json(['success' => false, 'status' => 400, 'message' => 'Email already exists. Please choose a different email']);
|
||||
}
|
||||
$add_newsletter_data = new news_letter;
|
||||
$add_newsletter_data->first_name = $request->input('first_name');
|
||||
$add_newsletter_data->email = trim($request->input('email'));
|
||||
$add_newsletter_data->save();
|
||||
return response()->json(['success' => true, 'status' => 200, 'message' => 'Newsletter added successfully']);
|
||||
} catch (QueryException $e) {
|
||||
if ($e->errorInfo[1] == 1062) {
|
||||
// Handle unique constraint violation exception (error code 1062)
|
||||
return response()->json(['success' => false, 'status' => 400, 'message' => 'Email already exists. Please choose a different email']);
|
||||
}
|
||||
// Handle other database-related exceptions if necessaryl']);
|
||||
return response()->json(['success' => false, 'status' => 500, 'message' => 'Database error occurred. Please try again later.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function view_newsletter() {
|
||||
|
||||
$view_newsletter_data = news_letter::all()->toArray();
|
||||
// dd($view_newsletter_data);
|
||||
return view('Admin.Pages.manage_newsletter.manage_newsletter', ['newsletter' => $view_newsletter_data]);
|
||||
}
|
||||
|
||||
public function store_rating(Request $request) {
|
||||
// Check if the user is authenticated
|
||||
if (!auth()->check()) {
|
||||
return response()->json(['success' => false, 'status' => 401]);
|
||||
}
|
||||
|
||||
$userIds = auth()->id();
|
||||
|
||||
// Data to be inserted or updated
|
||||
$data = [
|
||||
'principal_xid' => $userIds,
|
||||
'rating' => $request->input('star-rating'),
|
||||
];
|
||||
|
||||
// Use updateOrInsert to update or insert the rating
|
||||
user_rating::updateOrInsert(
|
||||
['principal_xid' => $userIds], $data
|
||||
);
|
||||
|
||||
return response()->json(['success' => true, 'status' => 200]);
|
||||
}
|
||||
|
||||
public function programs_by_country($countryId) {
|
||||
$country = Country::with(['programs' => function($query) {
|
||||
$query->where('is_active', 1);
|
||||
}])->findOrFail($countryId);
|
||||
|
||||
return response()->json(['program_country' => $country]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user