67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Home\Product;
|
|
|
|
use App\Models\Perfume;
|
|
use Illuminate\Contracts\View\View;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
#[Layout('components.layouts.home', [
|
|
'title' => 'Produk',
|
|
])]
|
|
class Index extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public string $productType = 'perfume';
|
|
|
|
public array $recommendations = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->recommendations = Perfume::with(['brand', 'categories', 'items'])
|
|
->withCount('items')
|
|
->orderBy('items_count', 'desc')
|
|
->take(5)
|
|
->get()
|
|
->map(function ($perfume) {
|
|
return [
|
|
'id' => $perfume->id,
|
|
'name' => $perfume->name,
|
|
'category' => $perfume->categories->first()?->name,
|
|
'price' => $perfume->sale_price,
|
|
'image' => $perfume->getFirstMediaUrl() ?: 'https://placehold.co/400x500/png?text='.urlencode($perfume->name),
|
|
'rating' => 4.5,
|
|
];
|
|
})
|
|
->toArray();
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
$perfumes = Perfume::with(['brand', 'categories', 'items'])
|
|
->latest()
|
|
->paginate(9)
|
|
->through(function ($perfume) {
|
|
return [
|
|
'id' => $perfume->id,
|
|
'name' => $perfume->name,
|
|
'category' => $perfume->categories->first()?->name,
|
|
'price' => $perfume->sale_price,
|
|
'image' => $perfume->getFirstMediaUrl() ?: 'https://placehold.co/400x500/png?text='.urlencode($perfume->name),
|
|
'rating' => 4.5,
|
|
'reviews' => $perfume->items->count(),
|
|
'is_new' => $perfume->created_at->diffInDays(now()) <= 30,
|
|
'colors' => ['#78350f', '#1f2937'],
|
|
];
|
|
});
|
|
|
|
return view('livewire.home.product.index', [
|
|
'pageTitle' => 'Produk',
|
|
'perfumes' => $perfumes,
|
|
]);
|
|
}
|
|
}
|