90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Home;
|
|
|
|
use App\Models\Brand;
|
|
use App\Models\ChooseUs;
|
|
use App\Models\Customer;
|
|
use App\Models\Faq;
|
|
use App\Models\PerfumeFeature;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('components.layouts.home', [
|
|
'title' => 'Beranda',
|
|
])]
|
|
class Index extends Component
|
|
{
|
|
public array $brands = [];
|
|
|
|
public array $perfumeFeatures = [];
|
|
|
|
public array $faqs = [];
|
|
|
|
public array $whyChooseUs = [];
|
|
|
|
public int $totalMembersCount = 0;
|
|
|
|
public $latestMembers = [];
|
|
|
|
public function mount()
|
|
{
|
|
$this->brands = Brand::orderBy('sort_order')
|
|
->get()
|
|
->map(fn(Brand $brand) => [
|
|
'name' => $brand->name,
|
|
'image' => $brand->getFirstMediaUrl('image') ? Storage::url($brand->getFirstMediaUrl('image')) : asset('assets/images/logo.png'),
|
|
])
|
|
->toArray();
|
|
|
|
$this->perfumeFeatures = PerfumeFeature::orderBy('sort_order')
|
|
->get()
|
|
->map(fn(PerfumeFeature $perfumeFeature) => [
|
|
'name' => $perfumeFeature->name,
|
|
'description' => $perfumeFeature->description,
|
|
])
|
|
->toArray();
|
|
|
|
$this->faqs = Faq::orderBy('sort_order')
|
|
->get()
|
|
->map(fn(Faq $faq) => [
|
|
'question' => $faq->question,
|
|
'answer' => $faq->answer,
|
|
])
|
|
->toArray();
|
|
|
|
$this->whyChooseUs = ChooseUs::orderBy('sort_order')
|
|
->get()
|
|
->map(fn(ChooseUs $chooseUs) => [
|
|
'name' => $chooseUs->name,
|
|
'description' => $chooseUs->description,
|
|
])
|
|
->toArray();
|
|
|
|
$this->totalMembersCount = Customer::whereNotNull('user_id')->count();
|
|
|
|
$this->latestMembers = Customer::whereNotNull('user_id')
|
|
->inRandomOrder()
|
|
->take(3)
|
|
->get();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.home.index', [
|
|
'pageTitle' => 'Beranda',
|
|
]);
|
|
}
|
|
|
|
public function goToProduct()
|
|
{
|
|
return redirect('/product');
|
|
}
|
|
|
|
public function goToVoucher()
|
|
{
|
|
return redirect('/voucher');
|
|
}
|
|
}
|