59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use App\Models\SystemConfiguration;
|
|
use App\Settings\SocialMediaSettings;
|
|
use App\Settings\SystemSettings;
|
|
use App\Support\Media\MediaPresenter;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function index(): Response
|
|
{
|
|
$categories = Category::whereHas('products')->get(['id', 'name', 'slug']);
|
|
|
|
$products = Product::where('is_active', true)
|
|
->with([
|
|
'categories',
|
|
'variants' => fn ($query) => $query
|
|
->with(['prices' => fn ($query) => $query->orderBy('type'), 'media'])
|
|
->orderBy('created_at'),
|
|
])
|
|
->get();
|
|
|
|
$products = $products->map(function ($product) {
|
|
$product->variants->each(function ($variant) {
|
|
$variant->setAttribute('images', MediaPresenter::collection($variant, 'images'));
|
|
});
|
|
|
|
return $product;
|
|
});
|
|
|
|
$configuration = SystemConfiguration::instance();
|
|
$logo = MediaPresenter::first($configuration, 'logo');
|
|
$logoUrl = $logo['url'] ?? null;
|
|
|
|
$settings = app(SystemSettings::class);
|
|
$socialSettings = app(SocialMediaSettings::class);
|
|
|
|
return Inertia::render('Home', [
|
|
'categories' => $categories,
|
|
'products' => $products,
|
|
'appName' => $settings->app_name ?? 'DST Collection',
|
|
'aboutApp' => $settings->about_app ?? '',
|
|
'contactEmail' => $settings->email ?? '',
|
|
'contactPhone' => $settings->phone ?? '',
|
|
'contactAddress' => $settings->address ?? '',
|
|
'logoUrl' => $logoUrl,
|
|
'instagramUrl' => $socialSettings->instagram_url ?? null,
|
|
'facebookUrl' => $socialSettings->facebook_url ?? null,
|
|
'tiktokUrl' => $socialSettings->tiktok_url ?? null,
|
|
]);
|
|
}
|
|
}
|