From a655f476292d8081a23653fc1b9228f4fb64faa4 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 5 Jan 2023 19:52:12 +0100 Subject: [PATCH] expand tech --- app/Http/Controllers/SitemapXmlController.php | 4 +-- app/Http/Controllers/TechniqueController.php | 5 +++ .../2023_01_05_172332_tech_type.php | 32 +++++++++++++++++++ resources/js/components/pages/Techniques.js | 7 +++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2023_01_05_172332_tech_type.php diff --git a/app/Http/Controllers/SitemapXmlController.php b/app/Http/Controllers/SitemapXmlController.php index 1bd7749..daa3699 100644 --- a/app/Http/Controllers/SitemapXmlController.php +++ b/app/Http/Controllers/SitemapXmlController.php @@ -24,12 +24,12 @@ class SitemapXmlController extends Controller $url = new SitemapUrl(); $url->path = '/tech'; - $url->lastmod = Technique::latest()->first()->created_at; + $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at; $url->changefreq = 'monthly'; $url->priority = 0.5; $urls[] = $url; - foreach (Technique::where('index', true)->get() as $tech) { + foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) { $url = new SitemapUrl(); $url->path = '/tech/'.rawurlencode($tech->name); $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now()); diff --git a/app/Http/Controllers/TechniqueController.php b/app/Http/Controllers/TechniqueController.php index a1ba20e..268c3f6 100644 --- a/app/Http/Controllers/TechniqueController.php +++ b/app/Http/Controllers/TechniqueController.php @@ -12,10 +12,15 @@ class TechniqueController extends Controller public function search(Request $request) { $validatedData = $request->validate([ 'phrase' => 'string|nullable', + 'type' => 'string|nullable', ]); $techs = Technique::where('index', '=', 1); + if (!empty($validatedData['type'])) { + $techs = $techs->where('type', '=', $validatedData['type']); + } + if (!empty($validatedData['phrase'])) { $search = $validatedData['phrase']; $techs = $techs->where(function (Builder $query) use ($search) { diff --git a/database/migrations/2023_01_05_172332_tech_type.php b/database/migrations/2023_01_05_172332_tech_type.php new file mode 100644 index 0000000..6d9577a --- /dev/null +++ b/database/migrations/2023_01_05_172332_tech_type.php @@ -0,0 +1,32 @@ +string('type')->default('tech'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('techniques', function(Blueprint $table) { + $table->dropColumn('type'); + }); + } +}; diff --git a/resources/js/components/pages/Techniques.js b/resources/js/components/pages/Techniques.js index 9334155..c206a31 100644 --- a/resources/js/components/pages/Techniques.js +++ b/resources/js/components/pages/Techniques.js @@ -20,7 +20,12 @@ const Techniques = () => { setLoading(true); window.document.title = i18n.t('techniques.heading'); axios - .get(`/api/tech`, { signal: ctrl.signal }) + .get(`/api/tech`, { + params: { + type: 'tech', + }, + signal: ctrl.signal + }) .then(response => { setError(null); setLoading(false); -- 2.39.2