274 lines
9.6 KiB
PHP
274 lines
9.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Rules\Recaptcha;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\View;
|
|
use Modules\CCMS\Models\Blog;
|
|
use Modules\CCMS\Models\Country;
|
|
use Modules\CCMS\Models\Enquiry;
|
|
use Modules\CCMS\Models\Institution;
|
|
use Modules\CCMS\Models\Page;
|
|
use Modules\CCMS\Models\Service;
|
|
use Modules\CCMS\Models\Slider;
|
|
use Modules\CCMS\Models\Test;
|
|
use Modules\CourseFinder\Models\Coop;
|
|
use Modules\CourseFinder\Models\Program;
|
|
use Modules\CourseFinder\Models\ProgramLevel;
|
|
use Modules\CourseFinder\Services\ProgramService;
|
|
|
|
class WebsiteController extends Controller
|
|
{
|
|
private $path;
|
|
protected $programService;
|
|
public function __construct(ProgramService $programService)
|
|
{
|
|
$this->programService = $programService;
|
|
$headerMenus = getAllHeaderMenusWithChildren();
|
|
$footerMenus = getAllFooterMenusWithChildren();
|
|
$this->path = config('app.client');
|
|
|
|
view()->share([
|
|
'headerMenus' => $headerMenus,
|
|
'footerMenus' => $footerMenus,
|
|
]);
|
|
}
|
|
|
|
public function home()
|
|
{
|
|
$data['firstImage'] = Slider::where('status', 1)->orderBy('order')->first();
|
|
$data['sliders'] = getSliders(limit: null, order: 'asc');
|
|
$data['counters'] = getCounters(limit: null, order: 'asc');
|
|
$data['successGalleries'] = getGalleriesByCategory(limit: 3, order: 'asc', category: 'voice-of-success');
|
|
$data['destinations'] = getDestinations(limit: null, order: 'asc');
|
|
$data['services'] = getServices(limit: null, order: 'asc');
|
|
$data['classes'] = getClasses(limit: null, order: 'asc');
|
|
$data['institutions'] = getInstitutions(limit: null, order: 'asc');
|
|
$data['faqs'] = getFAQs(limit: null, order: 'desc');
|
|
$data['testimonials'] = getTestimonials(limit: null, order: 'desc');
|
|
$data['blogs'] = getBlogs(limit: 4, order: 'desc');
|
|
$data['achievementGalleries'] = getGalleriesByCategory(limit: null, order: 'asc', category: 'achievement');
|
|
$data['visaGalleries'] = getGalleriesByCategory(limit: null, order: 'asc', category: 'visa-success');
|
|
$data['dishes'] = getGalleriesByCategory(limit: null, order: 'asc', category: 'dishes');
|
|
$page = $data['page'] = getPageWithChildrenBySlug(parent: null, slug: '/', limit: null, order: 'asc');
|
|
|
|
if (!$page) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$path = "client.$this->path.pages.$page->template";
|
|
|
|
if (!View::exists($path)) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
return view($path, $data);
|
|
}
|
|
|
|
public function blogSingle($alias)
|
|
{
|
|
$blog = $data["page"] = Blog::where('status', 1)
|
|
->where('slug', $alias)->first();
|
|
|
|
if (!$blog) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$data['categories'] = getBlogCategories(limit: null, order: 'desc');
|
|
|
|
$data['recentBlogs'] = Blog::where('status', 1)
|
|
->where('id', '!=', $blog->id)
|
|
->inRandomOrder()
|
|
->orderBy('created_at', 'desc')
|
|
->take(5)->get();
|
|
|
|
$blog->increment('views');
|
|
|
|
return view("client.$this->path.pages.blog-single-template", $data);
|
|
}
|
|
|
|
public function serviceSingle($alias)
|
|
{
|
|
$service = $data["page"] = Service::where('status', 1)
|
|
->where('slug', $alias)
|
|
->with('children', function ($query) {
|
|
$query->where('status', 1)
|
|
->orderBy('order');
|
|
})
|
|
->first();
|
|
|
|
if (!$service) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$data['allServices'] = Service::where('status', 1)
|
|
->where('parent_id', null)
|
|
->orderBy('created_at', 'desc')
|
|
->get();
|
|
|
|
$data['serviceFAQs'] = getFAQsByCategory(limit: null, order: 'desc', category: $service->slug);
|
|
|
|
|
|
|
|
if ($service->slug == 'test-preparation') {
|
|
$data['tests'] = Test::where(['status' => 1, 'parent_id' => null])->orderBy('order')->with('children', function ($query) {
|
|
$query->where('status', 1)
|
|
->orderBy('order');
|
|
})->get();
|
|
|
|
$data['testimonials'] = getTestimonials(limit: 5, order: 'desc');
|
|
return view("client.$this->path.pages.service-single-test-template", $data);
|
|
}
|
|
|
|
return view("client.$this->path.pages.service-single-template", $data);
|
|
}
|
|
|
|
public function countrySingle($alias)
|
|
{
|
|
$country = $data["page"] = Country::where('status', 1)
|
|
->where('slug', $alias)
|
|
->with('institutions', function ($query) {
|
|
$query->where('status', 1);
|
|
})
|
|
->first();
|
|
|
|
if (!$country) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$data['countryFAQs'] = getFAQsByCategory(limit: null, order: 'desc', category: $country->slug);
|
|
$data['countryInstitutions'] = $country->institutions;
|
|
|
|
$data['recentCountries'] = Country::where('status', 1)
|
|
->where('id', '!=', $country->id)
|
|
->inRandomOrder()
|
|
->orderBy('created_at', 'desc')
|
|
->take(5)->get();
|
|
|
|
return view("client.$this->path.pages.country-single-template", $data);
|
|
}
|
|
|
|
public function testSingle($alias)
|
|
{
|
|
$test = $data["page"] = Test::where('status', 1)
|
|
->where('slug', $alias)
|
|
->first();
|
|
|
|
if (!$test) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$data['children'] = Test::where('status', 1)
|
|
->where('parent_id', $test->id)
|
|
->get();
|
|
$data['testFAQs'] = getFAQsByCategory(limit: null, order: 'desc', category: $test->slug);
|
|
|
|
$data['allTests'] = Test::where('status', 1)
|
|
->where('parent_id', null)
|
|
->select('title', 'slug')
|
|
->get();
|
|
|
|
return view("client.$this->path.pages.test-single-template", $data);
|
|
}
|
|
|
|
public function loadPage(?string $parent = null, ?string $slug = null)
|
|
{
|
|
if ($slug === null) {
|
|
$slug = $parent;
|
|
$parent = null;
|
|
}
|
|
|
|
$page = getPageWithChildrenBySlug(parent: $parent, slug: $slug, limit: null, order: 'asc');
|
|
|
|
if (!$page) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
$path = "client.$this->path.pages.$page->template";
|
|
|
|
if (!View::exists($path)) {
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
return view($path, ['page' => $page]);
|
|
}
|
|
|
|
public function fallback()
|
|
{
|
|
return view("client.$this->path.errors.404");
|
|
}
|
|
|
|
public function coursefinder(Request $request)
|
|
{
|
|
$data['page'] = Page::where(['slug' => 'course-finder', 'status' => 1])->first();
|
|
$data['title'] = 'Program List';
|
|
$data['programs'] = $this->programService->findAll($request);
|
|
$data['countryOptions'] = Country::where('status', 1)->pluck('title', 'id');
|
|
|
|
$data['institutionOptions'] = Institution::query()
|
|
->when($request->filled('country_id'), function ($query) use ($request) {
|
|
$query->where('country_id', $request->country_id);
|
|
})
|
|
->pluck('title', 'id');
|
|
|
|
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
|
$data['intakeOptions'] = Program::INTAKE;
|
|
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
|
|
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
|
$data['statusOptions'] = config('constants.page_status_options');
|
|
|
|
return view("client.$this->path.pages.coursefinder-template", $data);
|
|
}
|
|
|
|
|
|
public function storeEnquiries(Request $request)
|
|
{
|
|
$request->merge([
|
|
'type' => $request->input('type', 'enquiries')
|
|
]);
|
|
try {
|
|
$rules = [
|
|
'type' => 'required|in:enquiries,booking',
|
|
'name' => 'required|string',
|
|
'email' => 'required|email',
|
|
'mobile' => 'nullable',
|
|
'subject' => 'nullable',
|
|
'class' => 'nullable',
|
|
'message' => 'nullable|max:250',
|
|
];
|
|
|
|
if (setting('enable_reCaptcha') == 1) {
|
|
$rules['g-recaptcha-response'] = ['required', new Recaptcha];
|
|
}
|
|
|
|
$messages = [
|
|
'email.email' => 'Must be a valid email address.',
|
|
'mobile.numeric' => 'Must be a valid phone number.',
|
|
'mobile.digits' => 'Must be a valid phone number.',
|
|
'g-recaptcha-response.required' => 'Please complete reCAPTCHA validation.',
|
|
'g-recaptcha-response' => 'Invalid reCAPTCHA.',
|
|
];
|
|
|
|
$validator = Validator::make($request->all(), $rules, $messages);
|
|
|
|
if ($validator->fails()) {
|
|
// dd($request->all());
|
|
return response()->json(['errors' => $validator->errors()], 422);
|
|
}
|
|
|
|
$validatedData = $validator->validated();
|
|
// $validatedData['type'] = 'enquiries'; // Set the type
|
|
|
|
Enquiry::create($validatedData);
|
|
|
|
// Enquiry::create($validator->validated());
|
|
|
|
return response()->json(['status' => 200, 'message' => "Thank you for reaching out! Your message has been received and we'll get back to you shortly."], 200);
|
|
} catch (\Exception $e) {
|
|
return response()->json(['status' => 500, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
}
|