master_template/app/Http/Controllers/WebsiteController.php

215 lines
7.8 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;
2024-06-18 18:40:14 +00:00
use App\Models\Advertisements;
2024-06-18 05:46:51 +00:00
use App\Models\Articles;
2024-06-23 11:17:56 +00:00
use App\Models\Comments;
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;
2024-06-21 07:44:04 +00:00
use App\Models\Popups;
2024-06-15 16:38:54 +00:00
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;
2024-06-23 11:17:56 +00:00
use Illuminate\Support\Facades\Route;
2024-06-18 05:46:51 +00:00
use App\Models\Videos;
2024-06-21 07:44:04 +00:00
use Share;
2024-06-10 12:21:58 +00:00
class WebsiteController extends Controller
{
private $path;
public function __construct()
{
2024-06-23 11:17:56 +00:00
$routes = Route::getRoutes();
// dd($routes);
// foreach ($routes as $route) {
// $name= $route->getName();
// dump($name);
// }
// dd('end');
2024-06-10 12:21:58 +00:00
$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();
$footerMenuItems = Menuitems::where(['parent_menu' => 0, "status" => 1, "menulocations_id" => 2])->with('children')->orderBy('display_order')->get();
2024-06-18 18:40:14 +00:00
$latestNews = News::where('status', 1)->inRandomOrder()->limit(4)->get();
2024-06-21 07:44:04 +00:00
$ads = Advertisements::where('status', 1)->where('parent_advertisement', 0)->get();
$adsWithChildren = Advertisements::where('status', 1)->where('parent_advertisement', 0)->orderBy('display_order')->with('children')->get();
$popup = Popups::where('status',1)->latest()->first();
2024-06-23 11:17:56 +00:00
$route = Route::getRoutes();
2024-06-18 05:46:51 +00:00
View::share(
[
'headerMenuItems' => $headerMenuItems,
'footerMenuItems' => $footerMenuItems,
2024-06-18 18:40:14 +00:00
'latestNews' => $latestNews,
'ads' => $ads,
2024-06-21 07:44:04 +00:00
'adsWithChildren' => $adsWithChildren,
'popup' => $popup
2024-06-18 05:46:51 +00:00
]
);
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)
{
2024-06-21 07:44:04 +00:00
$shareComponent = Share::currentPage()->facebook()->twitter()->whatsapp()->linkedin();
2024-06-18 05:46:51 +00:00
$news = News::where('alias', $alias)->where('status', 1)->first();
2024-06-21 07:44:04 +00:00
if (!$news) {
abort(404, 'News not found');
}
$news->views_count = $news->views_count + 1;
$news->save();
2024-06-23 11:17:56 +00:00
$newsWithComment = News::with('comments')->where('news_id', $news->news_id)->get();
// dd($newsWithComment->toArray());
2024-06-21 07:44:04 +00:00
$recentNews = News::where('status', 1)
->where('news_id', '!=', $news->news_id)
->inRandomOrder()
->limit(12)
->latest()
->get();
2024-06-23 11:17:56 +00:00
return view($this->path . '.news-detail', compact('news', 'recentNews','shareComponent','newsWithComment'));
2024-06-18 05:46:51 +00:00
}
2024-06-21 07:44:04 +00:00
2024-06-18 05:46:51 +00:00
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();
2024-06-21 07:44:04 +00:00
$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-18 05:46:51 +00:00
2024-06-21 07:44:04 +00:00
public function videoDetail($alias)
{
2024-06-20 10:57:33 +00:00
$data = Videos::where('alias', $alias)->where('status', 1)->first();
2024-06-21 07:44:04 +00:00
$recentNews = News::where('status', 1)->inRandomOrder()->limit(12)->latest()->get();
return view($this->path . '.video-detail', compact('data', 'recentNews'));
2024-06-20 10:57:33 +00:00
}
}