diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index c3bc981..8c2f107 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -41,7 +41,8 @@ class NewsController extends Controller public function store(Request $request) { - // dd($request->all()); + dd($request->all()); + $status = $request->input('status'); $isFeatured = $request->input('featured_news'); createActivityLog(NewsController::class, 'store', ' News store'); $validator = Validator::make($request->all(), [ @@ -68,6 +69,11 @@ class NewsController extends Controller } else { $requestData['featured_news'] = 'False'; } + if($status){ + $requestData['status'] = 1; + }else{ + $requestData['status'] = 0; + } array_walk_recursive($requestData, function (&$value) { $value = str_replace(env('APP_URL') . '/', '', $value); }); @@ -136,6 +142,7 @@ class NewsController extends Controller public function update(Request $request, $id) { + $status = $request->input('status'); $isFeatured = $request->input('featured_news'); createActivityLog(NewsController::class, 'update', ' News update'); @@ -159,6 +166,11 @@ class NewsController extends Controller } else { $filterData['featured_news'] = 'False'; } + if($status){ + $filterData['status'] = 1; + }else{ + $filterData['status'] = 0; + } array_walk_recursive($filterData, function (&$value) { $value = str_replace(env('APP_URL') . '/', '', $value); diff --git a/app/Http/Controllers/PopupsController.php b/app/Http/Controllers/PopupsController.php new file mode 100644 index 0000000..b05843f --- /dev/null +++ b/app/Http/Controllers/PopupsController.php @@ -0,0 +1,181 @@ +modelService = new CommonModelService($model); + $this->popupRepository = $popupRepository; + } + public function index(Request $request) + { + createActivityLog(PopupsController::class, 'index', ' Popups index'); + $data = Popups::where('status', '<>', -1)->orderBy('display_order')->get(); + + return view("crud.generated.popups.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(PopupsController::class, 'create', ' Popups create'); + $TableData = Popups::where('status', '<>', -1)->orderBy('display_order')->get(); + return view("crud.generated.popups.create", compact('TableData')); + } + + public function store(Request $request) + { + createActivityLog(PopupsController::class, 'store', ' Popups store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ], 500); + } + $request->request->add(['display_order' => getDisplayOrder('tbl_popups')]); + $requestData = $request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL') . '/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + $requestData['createdBy'] = auth()->user()->id; + $requestData['updatedBy'] = auth()->user()->id; + + $this->popupRepository->create($requestData); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Popups Created Successfully.'], 200); + } + return redirect()->route('popups.index')->with('success', 'The Popups created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Popups::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Popups::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(PopupsController::class, 'show', ' Popups show'); + $data = Popups::findOrFail($id); + + return view("crud.generated.popups.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(PopupsController::class, 'edit', ' Popups edit'); + $TableData = Popups::where('status', '<>', -1)->orderBy('display_order')->get(); + $data = Popups::findOrFail($id); + if ($request->ajax()) { + $html = view("crud.generated.popups.ajax.edit", compact('data'))->render(); + return response()->json(['status' => true, 'content' => $html], 200); + } + return view("crud.generated.popups.edit", compact('data', 'TableData')); + } + + + public function update(Request $request, $id) + { + createActivityLog(PopupsController::class, 'update', ' Popups update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ], 500); + } + $filterData = $request->except(['_method','_token']); + array_walk_recursive($filterData, function (&$value) { + $value = str_replace(env('APP_URL') . '/', '', $value); + }); + array_walk_recursive($filterData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + $this->popupRepository->update($id, $filterData); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Popups updated Successfully.'], 200); + } + // return redirect()->route('popups.index')->with('success','The Popups updated Successfully.'); + return redirect()->route('popups.index')->with('success', 'The Popups updated successfully.'); + } + + public function destroy(Request $request, $id) + { + createActivityLog(PopupsController::class, 'destroy', ' Popups destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(PopupsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status' => true, 'message' => 'The Popups Deleted Successfully.'], 200); + } + public function toggle(Request $request, $id) + { + createActivityLog(PopupsController::class, 'destroy', ' Popups destroy'); + $data = Popups::findOrFail($id); + $requestData = ['status' => ($data->status == 1) ? 0 : 1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(PopupsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status' => true, 'message' => 'The Popups Deleted Successfully.'], 200); + } +} diff --git a/app/Http/Controllers/WebsiteController.php b/app/Http/Controllers/WebsiteController.php index 6346857..611411e 100644 --- a/app/Http/Controllers/WebsiteController.php +++ b/app/Http/Controllers/WebsiteController.php @@ -11,6 +11,7 @@ use App\Models\Menuitems; use App\Models\News; use App\Models\News_type; use App\Models\Newscategories; +use App\Models\Popups; use App\Models\Provinces; use Illuminate\Http\Request; use App\Models\Teams; @@ -18,6 +19,7 @@ use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Mail; use App\Models\Videos; +use Share; class WebsiteController extends Controller { @@ -28,22 +30,20 @@ class WebsiteController extends Controller $this->path = config('app.client_path'); $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(); $latestNews = News::where('status', 1)->inRandomOrder()->limit(4)->get(); - // dd($recentNews); - $ads = Advertisements::where('status', 1)->where('parent_advertisement',0)->get(); - // dd($ads->toArray()); - $adsWithChildren = Advertisements::where('status',1)->where('parent_advertisement',0)->orderBy('display_order')->with('children')->get(); - // dd($adsWithChildren->toArray()); + $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(); View::share( [ 'headerMenuItems' => $headerMenuItems, 'footerMenuItems' => $footerMenuItems, 'latestNews' => $latestNews, 'ads' => $ads, - 'adsWithChildren' => $adsWithChildren + 'adsWithChildren' => $adsWithChildren, + 'popup' => $popup ] ); } @@ -96,11 +96,26 @@ class WebsiteController extends Controller public function newsDetail($alias) { + $shareComponent = Share::currentPage()->facebook()->twitter()->whatsapp()->linkedin(); $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')); + if (!$news) { + abort(404, 'News not found'); + } + + $news->views_count = $news->views_count + 1; + $news->save(); + + $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','shareComponent')); } + public function showHororscope() { $rashifal = Horoscopes::where('status', 1)->orderBy('display_order')->limit(12)->get(); @@ -174,13 +189,14 @@ class WebsiteController extends Controller 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')); + $data = News::where('provinces_id', $id)->where('status', 1)->orderBy('display_order')->paginate(9); + return view($this->path . '.single', compact('data', 'categoryTitle')); } - public function videoDetail($alias){ + public function videoDetail($alias) + { $data = Videos::where('alias', $alias)->where('status', 1)->first(); - $recentNews = News::where('status',1)->inRandomOrder()->limit(12)->latest()->get(); - return view($this->path . '.video-detail', compact('data','recentNews')); + $recentNews = News::where('status', 1)->inRandomOrder()->limit(12)->latest()->get(); + return view($this->path . '.video-detail', compact('data', 'recentNews')); } } diff --git a/app/Models/Advertisements.php b/app/Models/Advertisements.php index 381b17d..1ad363e 100644 --- a/app/Models/Advertisements.php +++ b/app/Models/Advertisements.php @@ -18,6 +18,7 @@ class Advertisements extends Model 'title', 'ad_categories_id', 'alias', + 'valid_till', 'parent_advertisement', 'thumb', 'link', diff --git a/app/Models/News.php b/app/Models/News.php index 351c3b1..ae92ef6 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -31,6 +31,7 @@ class News extends Model 'image', 'thumb', 'image_source', + 'views_count', 'display_order', 'status', 'remarks', diff --git a/app/Models/Popups.php b/app/Models/Popups.php new file mode 100644 index 0000000..8c9a39f --- /dev/null +++ b/app/Models/Popups.php @@ -0,0 +1,51 @@ +status == 1 ? ' Active ' : 'Inactive'; + } + + protected function createdBy(): Attribute + { + return Attribute::make( + get: fn ($value) => User::find($value) ? User::find($value)->name : '', + ); + } + + protected function updatedBy(): Attribute + { + return Attribute::make( + get: fn ($value) => User::find($value) ? User::find($value)->name : '', + ); + } + } \ No newline at end of file diff --git a/app/Repositories/Interface/PopupInterface.php b/app/Repositories/Interface/PopupInterface.php new file mode 100644 index 0000000..766ffb7 --- /dev/null +++ b/app/Repositories/Interface/PopupInterface.php @@ -0,0 +1,9 @@ +update($newDetails); + } +} diff --git a/composer.json b/composer.json index 1d235d5..4c12632 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "brian2694/laravel-toastr": "^5.59", "google/recaptcha": "^1.3", "guzzlehttp/guzzle": "^7.2", + "jorenvanhocht/laravel-share": "^4.2", "laravel/framework": "^10.10", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", diff --git a/composer.lock b/composer.lock index 0d8d275..dbf73d4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "21f9bae5dfa5a7adda4fc9f1ddad3d38", + "content-hash": "1393fa810c384d48b2c90249b5dca4c6", "packages": [ { "name": "brian2694/laravel-toastr", @@ -1294,6 +1294,69 @@ ], "time": "2024-02-14T15:11:21+00:00" }, + { + "name": "jorenvanhocht/laravel-share", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://github.com/jorenvh/laravel-share.git", + "reference": "86af334068038a840567ed62f2082fe3ac981476" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jorenvh/laravel-share/zipball/86af334068038a840567ed62f2082fe3ac981476", + "reference": "86af334068038a840567ed62f2082fe3ac981476", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "require-dev": { + "orchestra/testbench": "^6.13|^7.0", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Jorenvh\\Share\\Providers\\ShareServiceProvider" + ], + "aliases": { + "Share": "Jorenvh\\Share\\ShareFacade" + } + } + }, + "autoload": { + "psr-4": { + "Jorenvh\\Share\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joren Van Hocht", + "email": "joren@codeswitch.be", + "homepage": "https://codeswitch.be", + "role": "Developer" + } + ], + "description": "Optional package for Laravel to generate social share links.", + "homepage": "https://github.com/jorenvh/laravel-share", + "keywords": [ + "laravel", + "share", + "social links", + "social share links" + ], + "support": { + "issues": "https://github.com/jorenvh/laravel-share/issues", + "source": "https://github.com/jorenvh/laravel-share/tree/4.2.0" + }, + "time": "2022-02-11T17:20:09+00:00" + }, { "name": "laravel/framework", "version": "v10.44.0", diff --git a/config/app.php b/config/app.php index d39bbb2..e6fdc20 100644 --- a/config/app.php +++ b/config/app.php @@ -174,6 +174,7 @@ return [ Bibhuti\Installer\Providers\LaravelInstallerServiceProvider::class, Brian2694\Toastr\ToastrServiceProvider::class, Spatie\Permission\PermissionServiceProvider::class, + Jorenvh\Share\Providers\ShareServiceProvider::class, ])->toArray(), @@ -191,6 +192,7 @@ return [ 'aliases' => Facade::defaultAliases()->merge([ 'Toastr' => Brian2694\Toastr\Facades\Toastr::class, + 'Share' => Jorenvh\Share\ShareFacade::class, ])->toArray(), ]; diff --git a/config/laravel-share.php b/config/laravel-share.php new file mode 100644 index 0000000..f49e665 --- /dev/null +++ b/config/laravel-share.php @@ -0,0 +1,57 @@ + [ + 'facebook' => [ + 'uri' => 'https://www.facebook.com/sharer/sharer.php?u=', + ], + 'twitter' => [ + 'uri' => 'https://twitter.com/intent/tweet', + 'text' => 'Default share text', + ], + 'linkedin' => [ + 'uri' => 'https://www.linkedin.com/sharing/share-offsite', // oud: http://www.linkedin.com/shareArticle + 'extra' => ['mini' => 'true'], + ], + 'whatsapp' => [ + 'uri' => 'https://wa.me/?text=', + 'extra' => ['mini' => 'true'], + ], + 'pinterest' => [ + 'uri' => 'https://pinterest.com/pin/create/button/?url=', + ], + 'reddit' => [ + 'uri' => 'https://www.reddit.com/submit', + 'text' => 'Default share text', + ], + 'telegram' => [ + 'uri' => 'https://telegram.me/share/url', + 'text' => 'Default share text', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Font Awesome + |-------------------------------------------------------------------------- + | + | Specify the version of Font Awesome that you want to use. + | We support version 4 and 5. + | + | + */ + + 'fontAwesomeVersion' => 5, +]; diff --git a/database/migrations/2024_06_21_041250_add_views_count_on_news_table.php b/database/migrations/2024_06_21_041250_add_views_count_on_news_table.php new file mode 100644 index 0000000..0194af4 --- /dev/null +++ b/database/migrations/2024_06_21_041250_add_views_count_on_news_table.php @@ -0,0 +1,28 @@ +unsignedInteger('views_count')->nullable()->after('image_source'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('news', function (Blueprint $table) { + $table->dropColumn('views_count'); + }); + } +}; diff --git a/database/migrations/2024_06_21_042528_add_valid_till_in_advertisement_table.php b/database/migrations/2024_06_21_042528_add_valid_till_in_advertisement_table.php new file mode 100644 index 0000000..152f294 --- /dev/null +++ b/database/migrations/2024_06_21_042528_add_valid_till_in_advertisement_table.php @@ -0,0 +1,28 @@ +date('valid_till')->nullable()->after('parent_advertisement'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('advertisements', function (Blueprint $table) { + $table->dropColumn('valid_till'); + }); + } +}; diff --git a/database/migrations/2024_06_21_044940_create_popup_table.php b/database/migrations/2024_06_21_044940_create_popup_table.php new file mode 100644 index 0000000..dd58cf4 --- /dev/null +++ b/database/migrations/2024_06_21_044940_create_popup_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('title')->nullable(); + $table->string('description')->nullable(); + $table->string('image')->nullable(); + $table->date('valid_till')->nullable(); + $table->string('link')->nullable(); + $table->integer('status')->nullable(); + $table->integer('display_order')->nullable(); + $table->integer('createdBy')->nullable(); + $table->integer('updatedBy')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('popups'); + } +}; diff --git a/public/js/share.js b/public/js/share.js new file mode 100644 index 0000000..baa1186 --- /dev/null +++ b/public/js/share.js @@ -0,0 +1,20 @@ +var popupSize = { + width: 780, + height: 550 +}; + +$(document).on('click', '.social-button', function (e) { + var verticalPos = Math.floor(($(window).width() - popupSize.width) / 2), + horisontalPos = Math.floor(($(window).height() - popupSize.height) / 2); + + var popup = window.open($(this).prop('href'), 'social', + 'width=' + popupSize.width + ',height=' + popupSize.height + + ',left=' + verticalPos + ',top=' + horisontalPos + + ',location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1'); + + if (popup) { + popup.focus(); + e.preventDefault(); + } + +}); \ No newline at end of file diff --git a/resources/lang/vendor/laravel-share/en/laravel-share-fa5.php b/resources/lang/vendor/laravel-share/en/laravel-share-fa5.php new file mode 100644 index 0000000..c35994e --- /dev/null +++ b/resources/lang/vendor/laravel-share/en/laravel-share-fa5.php @@ -0,0 +1,11 @@ + '
{{label("Sn.")}} | +{{ label("title") }} | +{{ label("image") }} | +{{ label("valid_till") }} | +{{ label("link") }} | +{{ label("createdBy") }} | +{{ label("updatedBy") }} | +{{ label("Action") }} + | +
---|---|---|---|---|---|---|---|
{{ $i++ }} | {{ $item->title }} | +{{ showImageThumb($item->image) }} | +{{ myDate($item->valid_till) }} | +{{ $item->link }} | +{{ $item->createdBy }} | +{{ $item->updatedBy }} | +
+
+
+
+
+
+
+ |
+
Title : {{$data->title}}
Description : {{$data->description}}
Image : {{$data->image}}
Valid Till : {{$data->valid_till}}
Link : {{$data->link}}
Status : {{$data->status == 1 ? 'Active' : 'Inactive'}}
Display Order : {{$data->display_order}}
Created On : {{$data->created_at}}
+Created By : {{$data->createdBy}}
+Updated On : {{$data->updated_at}}
+Updated By : {{$data->updatedBy}}
+ +