46 lines
1.8 KiB
PHP
46 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use App\Services\CountryCatalogue;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class PublicPortalController extends Controller
|
|
{
|
|
public function opportunities(Request $request): Response
|
|
{
|
|
$filters = $request->validate(['q' => ['nullable', 'string', 'max:120'], 'sector' => ['nullable', 'string', 'max:80']]);
|
|
|
|
return Inertia::render('PortalInvestidor', ['initialView' => 'opportunities', 'initialQuery' => $filters['q'] ?? '', 'initialSector' => $filters['sector'] ?? '']);
|
|
}
|
|
|
|
public function sector(string $slug): Response
|
|
{
|
|
$sector = Sector::where('slug', $slug)->where('is_active', true)->firstOrFail();
|
|
|
|
return Inertia::render('portal/services', ['section' => 'sector', 'sector' => $sector->only(['name', 'slug', 'description', 'short_description']),
|
|
'opportunities' => $sector->opportunities()->published()->latest('published_at')->limit(12)->get(['title', 'slug', 'province', 'summary'])]);
|
|
}
|
|
|
|
public function opportunity(string $slug): Response
|
|
{
|
|
return $this->detail($slug, 'detail');
|
|
}
|
|
|
|
public function interest(?string $slug = null): Response
|
|
{
|
|
return $slug ? $this->detail($slug, 'interest') : Inertia::render('PortalInvestidor', ['initialView' => 'interest', 'countries' => app(CountryCatalogue::class)->all()]);
|
|
}
|
|
|
|
private function detail(string $slug, string $view): Response
|
|
{
|
|
$opportunity = Opportunity::with('sector:id,name,slug')->published()->where('slug', $slug)->firstOrFail();
|
|
|
|
return Inertia::render('PortalInvestidor', ['initialView' => $view, 'initialOpportunity' => $opportunity, 'countries' => app(CountryCatalogue::class)->all()]);
|
|
}
|
|
}
|