TanchoToplineCargo/app/Http/Controllers/WebsiteController.php
2024-05-08 09:13:25 +00:00

238 lines
8.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Mail\ContactMail;
use App\Mail\QuoteMail;
use App\Models\CompanyArticle;
use App\Models\Companyarticles;
use App\Models\Franchises;
use App\Models\Menuitems;
use App\Models\Menulocations;
use App\Models\News;
use App\Models\Partners;
use App\Models\Services;
use App\Models\Sliders;
use App\Models\Teams;
use App\Models\Testimonials;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Mail;
class WebsiteController extends Controller
{
private $path;
public function __construct()
{
$this->path = config('app.client_path');
$headerMenu = Menulocations::where('alias', 'header-menu')->first();
$headerMenuItems = Menuitems::where('menulocations_id', $headerMenu->menulocation_id)->where('status','<>',-1)->where('parent_menu', 0)->with('children')->orderBy('display_order', 'asc')->get();
$footerMenu = Menulocations::where('alias', 'footer-menu')->first();
$footerMenuItems = Menuitems::where('menulocations_id', $footerMenu->menulocation_id)->where('status','<>',-1)->where('parent_menu', 0)->with('children')->orderBy('display_order', 'asc')->get();
// dd($footerMenuItems);
$popularNews = News::inRandomOrder()->inRandomOrder()->take(3)->get();
View::share([
'headerMenuItems' => $headerMenuItems,
'footerMenuItems' => $footerMenuItems,
'popularNews' => $popularNews
]);
}
// public static function index(Request $request, $menu_id = "")
// {
// dd("test");
// $pathInfo = ltrim($request->getPathInfo(), '/');
// $r = explode('/', $pathInfo);
// $menu_alias = end($r);
// $menu_alias1 = str_replace("_", "-", $menu_alias);
// $menuItem = DB::table("menuitems")->where("alias", $menu_alias)->orWhere("alias", $menu_alias1)->get()[0];
// switch ($menuItem->type) {
// case 'tbl_contacts':
// $contact = DB::table("contacts")->where("contact_id", $menuItem->ref)->get()[0];
// return view("client." . env("CLIENT_PATH") . ".inside.contact", compact('contact'));
// // break;
// case 'tbl_countries':
// $countries = DB::table("countries")->where("article_id", $menuItem->ref)->get()[0];
// return view("client." . env("CLIENT_PATH") . ".inside.country_single", compact('country'));
// break;
// case 'tbl_companyarticles':
// $article = DB::table("companyarticles")->where("article_id", $menuItem->ref)->get()[0];
// return view("client." . env("CLIENT_PATH") . ".inside.article", compact('article'));
// //break;
// case 'tbl_recruitmentarticles':
// $recruitmentarticle = DB::table("recruitmentarticles")->where("article_id", $menuItem->ref)->get()[0];
// $article = $recruitmentarticle;
// return view("client." . env("CLIENT_PATH") . ".inside.recruitmentArticle", compact('recruitmentarticle', 'article'));
// case 'tbl_otherarticles':
// $cruiserecruiment = DB::table("otherarticles")->where("article_id", $menuItem->ref)->get()[0];
// $article = $cruiserecruiment;
// return view("client." . env("CLIENT_PATH") . ".inside.cruiserecruitment", compact('cruiserecruiment', 'article'));
// default:
// // echo $menuItem->alias;die;
// if ($menuItem->ref == "/")
// return view("client." . env("CLIENT_PATH") . ".welcome");
// else if ($menuItem->ref == "#")
// return view("client." . env("CLIENT_PATH") . ".welcome");
// else
// return view("client." . env("CLIENT_PATH") . ".inside" . '/' . ltrim($menuItem->ref));
// }
// }
public function home()
{
$data["sliders"] = Sliders::where('status', 1)->latest()->get();
$data["franchises"] = Franchises::latest()->take(4)->get();
$data["testimonials"] = Testimonials::where('status', 1)->latest()->get();
<<<<<<< HEAD
$data['services'] = Services::take(6)->get();
=======
$data['services'] = Services::latest()->where('parent_service',null)->take(6)->get();
>>>>>>> 9fa6a5d79720007756721d82c4fde70e31a0f1f1
$data['partners'] = Partners::latest()->get();
$data["news"] = News::latest()->take(6)->get();
$data['whyChooseUs'] = Companyarticles::where('status', 1)
->where('alias', 'why-choose-us')
->with('children')
->first();
$data['homecontent'] = Companyarticles::where('status', 1)->where('alias', 'global-supplier')->latest()->first();
$data['whychoose'] = Companyarticles::where('status', 1)
->where('alias', 'why-choose-us')
->with('children')
->first();
return view("client.$this->path.welcome", $data);
}
public function showArticle($alias)
{
$whyChooseUs = Companyarticles::where('status', 1)
->where('alias', 'why-choose-us')
->with('children')
->first();
$article = Companyarticles::where('status', 1)
->where('parent_article', 0)
->where('alias', $alias)
->with('children')
->first();
$teams = Teams::where('status', 1)->latest()->get();
return view("client.$this->path.article-single", compact('teams', 'alias', 'article','whyChooseUs'));
}
public function teams()
{
$teams = Teams::where('status', 1)->orderBy('display_order')->get();
return view("client.$this->path.teams", compact('teams'));
}
public function testimonials()
{
$testimonials = Testimonials::where('status', 1)->latest()->get();
return view("client.$this->path.testimonials", compact('testimonials'));
}
public function franchise()
{
$franchises = Franchises::latest()->get();
return view("client.$this->path.franchise", compact('franchises'));
}
public function news()
{
$news = News::where('status', 1)
->latest()
->paginate(3);
return view("client.$this->path.news", compact('news'));
}
public function showNews($alias)
{
$news = News::where('alias', $alias)->latest()->first();
return view("client.$this->path.news-single", compact('news'));
}
public function showFranchise($alias)
{
$content = Franchises::where('alias', $alias)->first();
return view('client.topCargo.franchise-single', compact('content'));
}
public function showService($alias)
{
$serviceLists = Services::where('status', 1)
->whereNull('parent_service')
->orWhere('parent_service', 0)
->select(['title', 'alias'])
->get();
$service = Services::where('alias', $alias)->where('status','<>',-1)->with('children',fn($query)=>$query->latest())->first();
return view('client.topCargo.service-single', compact('service', 'serviceLists'));
}
public function contact()
{
return view("client.$this->path.contact");
}
public function quote()
{
return view("client.$this->path.quote");
}
public function tracking()
{
return view("client.$this->path.tracking");
}
public function sendEmail(Request $request)
{
$identifier = $request->input('identifier');
if ($identifier == "contact") {
$validated = $request->validate([
'name' => 'required|min:3|max:255',
'email' => 'required|email',
'message' => 'required|min:10',
'phone' => 'required|string|regex:/^98\d{8}$/',
]);
$sent = Mail::to(SITEVARS->email)->send(new ContactMail($validated));
if ($sent) {
return response()->json(['success' => 'Email sent successfully']);
} else {
return response()->json(['error' => 'Failed to send email'], 500);
}
} else {
$validated = $request->validate([
'firstname' => 'required|string',
'lastname' => 'required|string',
'email' => 'required|email',
'citydeparture' => 'required|string',
'DeliverCity' => 'required|string',
'weight' => 'required|numeric',
'specialinfo' => 'nullable|string',
'freightType' => 'required|array',
'freightType.*' => 'required|string',
]);
$sent = Mail::to(SITEVARS->email)->send(new QuoteMail($validated));
if ($sent) {
return response()->json(['success' => 'Email sent successfully']);
} else {
return response()->json(['error' => 'Failed to send email'], 500);
}
}
}
}