From 09e544d361a448d658a3ee1ed1fdf0a7fe7bb55b Mon Sep 17 00:00:00 2001 From: Mohamed Jinas Date: Mon, 11 Jan 2021 19:36:39 +0500 Subject: [PATCH] Caching and og title --- app/Http/Controllers/NameSpaceController.php | 12 +++++++++--- config/karudhaas.php | 3 +++ resources/views/articles/show.blade.php | 2 +- resources/views/namespaces/show.blade.php | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/NameSpaceController.php b/app/Http/Controllers/NameSpaceController.php index 7f094be..3913371 100644 --- a/app/Http/Controllers/NameSpaceController.php +++ b/app/Http/Controllers/NameSpaceController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use App\Article; class NameSpaceController extends Controller @@ -17,11 +18,16 @@ class NameSpaceController extends Controller if (!array_key_exists($namespace, config('karudhaas.topic_filters'))) return redirect('/namespaces'); $options = config("karudhaas.topic_filters." . $namespace); + + $articles = Cache::remember("articles.$namespace", 600, function () use ($options) { + return Article::with('source')->whereHas('topics', function ($q) use ($options) { + $q->whereIn('slug', $options["keys"]); + })->latest('published_date')->limit(8)->get(); + }); + return view('namespaces.show', [ 'options' => $options, - 'articles' => Article::with('source')->whereHas('topics', function ($q) use ($options) { - $q->whereIn('slug', $options["keys"]); - })->latest('published_date')->paginate(8) + 'articles' => $articles ]); } } diff --git a/config/karudhaas.php b/config/karudhaas.php index a6f32a5..cbd3ab0 100644 --- a/config/karudhaas.php +++ b/config/karudhaas.php @@ -6,6 +6,7 @@ return [ "covid19" => [ "dv_name" => "ކޮރޯނާ ވައިރަސް", + "en_name" => "coronavirus", "description" => "ކޮރޯނާ ވައިރަހާއި ބެހޭ ޙަބަރުތަކުގެ އެންމެފަހުގެ އަޕްޑޭޓް.", "keys" => ["covid19", "covid-19", "corona_virus", "covid_19", "coronavirus"], "color" => "red" @@ -14,6 +15,7 @@ return [ "sports" => [ "dv_name" => "ކުޅިވަރު", + "en_name" => "sports", "description" => "ކުޅިވަރުގެ ތަފާތު ޙަބަރުތަށް", "keys" => [ "football", "sport", "kulhivaru", "maldives_national_football_tea", "football_association_of_maldiv", "local_sports", "spanish_league", @@ -25,6 +27,7 @@ return [ "business" => [ "dv_name" => "ވިޔަފާރި", + "en_name" => "business", "description" => "ފިޔަފާރިއާ ބެހޭ އެންމެ ފަހުގެ ޙަބަރުތަށް", "keys" => [ "tourism", "sme_loan","sme_bank","public_companies","mtcc","tourists","world_tourism_day_","mtcc_shares","google","guest_house","fish_products","tax", "business", "dhiraagu", diff --git a/resources/views/articles/show.blade.php b/resources/views/articles/show.blade.php index caefb1d..fe80491 100644 --- a/resources/views/articles/show.blade.php +++ b/resources/views/articles/show.blade.php @@ -6,7 +6,7 @@ - + diff --git a/resources/views/namespaces/show.blade.php b/resources/views/namespaces/show.blade.php index fa54cd0..23b3834 100644 --- a/resources/views/namespaces/show.blade.php +++ b/resources/views/namespaces/show.blade.php @@ -1,5 +1,20 @@ + + {{ucfirst($options['en_name'])}} | Karudhaas + + + + + + + + + + + + +