diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php new file mode 100644 index 0000000..e9d1f40 --- /dev/null +++ b/app/Http/Controllers/OrganizationController.php @@ -0,0 +1,50 @@ + $this->organizations(), + 'technologies' => $this->technologies(), + 'filterTechnology' => null, + ]); + } + + public function indexByTechnology(string $filterTechnology) + { + return view('organizations.index', [ + 'organizations' => $this->organizations($filterTechnology), + 'technologies' => $this->technologies(), + 'filterTechnology' => $filterTechnology, + ]); + } + + private function organizations(?string $filterTechnology = null) + { + return Cache::remember('orgs-list-filter[' . $filterTechnology . ']', 3600, function () use ($filterTechnology) { + return Organization::when(! is_null($filterTechnology), function (Builder $query) use ($filterTechnology) { + $query->whereHas('technologies', function (Builder $query) use ($filterTechnology) { + $query->where('slug', $filterTechnology); + }); + })->with('sites') // @todo: Do a subquery for just the first site aaron francis style? + ->orderBy('featured_at', 'desc') + ->orderBy('created_at', 'desc') + ->get(); + }); + } + + private function technologies() + { + return Cache::remember('active-organizations', 3600, function () { + return Technology::whereHas('organizations')->orderBy('name')->get(); + }); + } +} diff --git a/app/Livewire/OrgsList.php b/app/Livewire/OrgsList.php deleted file mode 100644 index ca1b3dc..0000000 --- a/app/Livewire/OrgsList.php +++ /dev/null @@ -1,44 +0,0 @@ -orderBy('name')->get(); - } - - #[Computed] - public function organizations() - { - return Cache::remember('orgs-list-filter[' . $this->filterTechnology . ']', 3600, function () { - return Organization::when(! is_null($this->filterTechnology), function (Builder $query) { - $query->whereHas('technologies', function (Builder $query) { - $query->where('slug', $this->filterTechnology); - }); - })->with('sites') // @todo: Do a subquery for just the first site aaron francis style? - ->orderBy('featured_at', 'desc') - ->orderBy('created_at', 'desc') - ->get(); - }); - } - - public function render() - { - return view('livewire.orgs-list'); - } -} diff --git a/resources/views/livewire/orgs-list.blade.php b/resources/views/components/orgs-list.blade.php similarity index 92% rename from resources/views/livewire/orgs-list.blade.php rename to resources/views/components/orgs-list.blade.php index 4b55df3..124e774 100644 --- a/resources/views/livewire/orgs-list.blade.php +++ b/resources/views/components/orgs-list.blade.php @@ -8,7 +8,7 @@ class="{{ $filterTechnology == null ? 'border-tighten-yellow text-black hover:bo All - @foreach ($this->technologies as $tech) + @foreach ($technologies as $tech) - @foreach ($this->organizations as $org) + @foreach ($organizations as $org) @endforeach diff --git a/resources/views/home.blade.php b/resources/views/organizations/index.blade.php similarity index 84% rename from resources/views/home.blade.php rename to resources/views/organizations/index.blade.php index 00e2bf4..8273982 100644 --- a/resources/views/home.blade.php +++ b/resources/views/organizations/index.blade.php @@ -1,5 +1,5 @@ - +

About

diff --git a/resources/views/technologies/show.blade.php b/resources/views/technologies/show.blade.php deleted file mode 100644 index 18ad4d1..0000000 --- a/resources/views/technologies/show.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/routes/web.php b/routes/web.php index b45a9ab..2580594 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,11 +1,12 @@ name('home'); +Route::get('/', [OrganizationController::class, 'index'])->name('home'); Route::get('orgs/{organization}', function (Organization $organization) { return view('organizations.show', ['organization' => $organization]); })->name('organizations.show'); @@ -16,7 +17,7 @@ require __DIR__ . '/auth.php'; -Route::view('{technology}', 'technologies.show')->name('technologies.show'); +Route::get('{technology}', [OrganizationController::class, 'indexbyTechnology'])->name('technologies.show'); /*