From 96b0235470968e0a9c67941fd2b1710745edab5c Mon Sep 17 00:00:00 2001 From: jovialcore Date: Wed, 11 Oct 2023 20:20:42 +0100 Subject: [PATCH] added nav bar with pils nect i list the company and creating an in scroller- will add search in the future --- app/Http/Controllers/CompanyController.php | 5 +- app/Services/CompanyService.php | 4 +- app/Traits/companyPreviewTrait.php | 15 ++ resources/views/admin/company/index.blade.php | 2 +- resources/views/admin/company/show.blade.php | 175 ++++++++++++++++++ .../views/admin/company/showCompany.blade.php | 47 ----- routes/web.php | 2 +- 7 files changed, 199 insertions(+), 51 deletions(-) create mode 100644 resources/views/admin/company/show.blade.php delete mode 100644 resources/views/admin/company/showCompany.blade.php diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 4023489..c239402 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -46,6 +46,9 @@ public function show(int $id): View { $company = $this->companyService->showCompany($id); - return view('admin.company.show', $company); + + + + return view('admin.company.show', ['company' => $company ]); } } diff --git a/app/Services/CompanyService.php b/app/Services/CompanyService.php index fda8300..3691bee 100644 --- a/app/Services/CompanyService.php +++ b/app/Services/CompanyService.php @@ -5,6 +5,7 @@ namespace App\Services; use App\Models\Company; +use App\Traits\companyPreviewTrait; use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; @@ -13,6 +14,7 @@ class CompanyService { + use companyPreviewTrait; public function getAllCompanies(): array { $companies = Company::all(); @@ -50,7 +52,7 @@ public function storeCompanyData(Request $request, Company $company): Company public function showCompany(int $id): Company { - $company = Company::find($id); + $company = $this->companyWithTechData()->find($id); return $company; } } diff --git a/app/Traits/companyPreviewTrait.php b/app/Traits/companyPreviewTrait.php index ffb3bbc..ffd992b 100644 --- a/app/Traits/companyPreviewTrait.php +++ b/app/Traits/companyPreviewTrait.php @@ -1,5 +1,7 @@ where('name', $company)->first(); } + + public function companyWithTechData() + { + + return Company::with(['plangs' => function ($query) { + $query->where('is_draft', 1)->where('is_published', 0)->with('frameworks', function ($query) { + $query->withWhereHas('companies', function ($query) { + // I don't now why I can't access the pivot of frameworks directly on frameworks collection exceptI use withWhereHas on Companies -- should look into it some time in future but for now, lets make do with how it is working now + $query->where('is_draft', 1)->where('is_published', 0); + }); + }); + }]); + } } diff --git a/resources/views/admin/company/index.blade.php b/resources/views/admin/company/index.blade.php index eebb182..df7197b 100644 --- a/resources/views/admin/company/index.blade.php +++ b/resources/views/admin/company/index.blade.php @@ -39,7 +39,7 @@ class="avatar avatar-xs pull-up" title="Lilian Fuller">