master_template/app/Http/Controllers/WebsiteController.php

183 lines
6.7 KiB
PHP
Raw Normal View History

2024-06-10 12:21:58 +00:00
<?php
namespace App\Http\Controllers;
2024-06-18 05:46:51 +00:00
use App\Mail\sendEmail;
use App\Models\Articles;
2024-06-15 16:38:54 +00:00
use App\Models\Economies;
2024-06-18 05:46:51 +00:00
use App\Models\Horoscopes;
use App\Models\Menuitems;
2024-06-15 16:38:54 +00:00
use App\Models\News;
use App\Models\News_type;
use App\Models\Newscategories;
use App\Models\Provinces;
2024-06-18 05:46:51 +00:00
use Illuminate\Http\Request;
use App\Models\Teams;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Mail;
use App\Models\Videos;
2024-06-10 12:21:58 +00:00
class WebsiteController extends Controller
{
private $path;
public function __construct()
{
$this->path = config('app.client_path');
2024-06-18 05:46:51 +00:00
$headerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 1])->with('children')->orderBy('display_order')->get();
// dd($headerMenuItems->toArray());
$footerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 2])->with('children')->orderBy('display_order')->get();
// dd($footerMenuItems->toArray());
$recentNews = News::where('status', 1)->inRandomOrder()->limit(4)->get();
View::share(
[
'headerMenuItems' => $headerMenuItems,
'footerMenuItems' => $footerMenuItems,
'recentNews' => $recentNews,
]
);
2024-06-10 12:21:58 +00:00
}
2024-06-18 05:46:51 +00:00
public function home()
{
$data['featuredNews'] = News::where('featured_news', "True")->where('status', 1)->first();
2024-06-15 16:38:54 +00:00
$data['provinces'] = Provinces::with('provinceNews')->limit(5)->get();
$data['categories'] = Newscategories::with('news')->get();
$data['interviews'] = Newscategories::with('interviewNews')->get();
$data['politics'] = Newscategories::with('politicNews')->get();
// $data['economics'] = Newscategories::with('news')->inRandomOrder()->get();
$data['economics'] = Economies::with('news')
2024-06-18 05:46:51 +00:00
->orderBy('display_order')
->where('status', 1)
->get();
2024-06-15 16:38:54 +00:00
$data['sports'] = Newscategories::with('sportNews')->get();
$data['cultural'] = Newscategories::with('culturalNews')->get();
$data['technology'] = Newscategories::with('technologyNews')->get();
$data['entertainment'] = Newscategories::with('entertainmentNews')->get();
2024-06-15 18:30:09 +00:00
$data['branches'] = Newscategories::with('branchesNews')->get();
2024-06-18 05:46:51 +00:00
$data['videos'] = Videos::where('status', 1)->orderBy('display_order')->get();
$data['horoscope'] = Horoscopes::where('status', 1)->orderBy('display_order')->get();
// dd($data['videos']);
2024-06-15 16:38:54 +00:00
$data['internationalNews'] = News_type::with('news')->get();
2024-06-18 05:46:51 +00:00
// dd($data['internationalNews']->toArray());
2024-06-15 16:38:54 +00:00
// dd($data['internationalNews']);
2024-06-18 05:46:51 +00:00
return view($this->path . '.home', $data);
}
public function single($alias)
{
$categoryId = Newscategories::where('alias', $alias)->pluck('category_id')->first();
$categoryTitle = Newscategories::where('alias', $alias)->pluck('nepali_title')->first();
$data = News::where('newscategories_id', $categoryId)->where('status', 1)->orderBy('display_order')->paginate(9);
return view($this->path . '.single', compact('data', 'categoryTitle'));
}
public function newsDetail($alias)
{
$news = News::where('alias', $alias)->where('status', 1)->first();
$recentNews = News::where('status', 1)->where('news_id', '!=', $news->news_id)->inRandomOrder()->limit(12)->latest()->get();
return view($this->path . '.news-detail', compact('news', 'recentNews'));
}
public function showHororscope()
{
$rashifal = Horoscopes::where('status', 1)->orderBy('display_order')->limit(12)->get();
return view($this->path . '.rashifal', compact('rashifal'));
}
public function showInternational($alias)
{
$categoryTitle = News_type::where('alias', $alias)->value('title_nepali');
$data = News::where('news_type_id', 1)
->where('status', 1)->orderBy('display_order')->paginate(9);
return view($this->path . '.single', compact('data', 'categoryTitle'));
}
public function showVideos()
{
2024-06-18 10:41:58 +00:00
$videos = Videos::where('status', 1)->orderBy('display_order')->paginate(7);
// dd($videos->toArray());
return view($this->path . '.video', compact('videos'));
2024-06-18 05:46:51 +00:00
}
public function showAboutus($alias)
{
$data['aboutus'] = Articles::where('alias', $alias)->where('status', 1)->first();
$data['teams'] = Teams::where('status', 1)->orderBy('display_order')->get();
return view($this->path . '.about-us', $data);
2024-06-13 15:17:05 +00:00
}
2024-06-18 05:46:51 +00:00
public function showArtilce($alias)
{
$data['article'] = Articles::with('childrens')->where('alias', $alias)->where('status', 1)->first();
return view($this->path . '.article', $data);
2024-06-10 12:21:58 +00:00
}
2024-06-15 16:38:54 +00:00
2024-06-18 05:46:51 +00:00
public function showContact()
{
return view($this->path . '.contact');
}
public function sendEmail(Request $request)
{
if ($request->input('accepted') == 'on') {
$requestData = $request->except(['_token', 'accepted']);
$validator = Validator::make($requestData, [
'title' => 'required|string|max:255',
'email' => 'required|email',
'phone_number' => 'required|regex:/\d{10}/',
'secondary_number' => 'nullable|regex:/\d{10}/',
'message' => 'required|string',
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$validated = $validator->validated();
try {
Mail::to(SITEVARS->email)->send(new SendEmail($validated));
return response()->json(['success' => 'Email sent successfully']);
} catch (\Exception $e) {
return response()->json(['error' => 'Failed to send email'], 500);
}
} else {
return response()->json(['error' => 'Acceptance checkbox is required'], 400);
}
}
public function showProvinces($id)
{
$categoryTitle = Provinces::where('province_id', $id)->pluck('province_nepali_name')->first();
$data = News::where('provinces_id',$id)->where('status',1)->orderBy('display_order')->paginate(9);
return view($this->path . '.single', compact('data','categoryTitle'));
2024-06-15 16:38:54 +00:00
}
2024-06-10 12:21:58 +00:00
}
2024-06-18 05:46:51 +00:00
// public function single($alias)
// {
// $categoryId = Newscategories::where('alias', $alias)->pluck('category_id')->first();
// $categoryTitle = Newscategories::where('alias', $alias)->pluck('nepali_title')->first();
// $data = News::where('newscategories_id', $categoryId)->where('status', 1)->orderBy('display_order')->paginate(9);
// return view($this->path . '.single', compact('data', 'categoryTitle'));
// }