Initial Commit
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Stylist\Services;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Blog\Models\Blog;
|
||||
use Modules\Faq\Models\Faq;
|
||||
use Modules\News\Models\News;
|
||||
use Modules\Products\Models\Product;
|
||||
use Modules\Team\Models\TeamMember;
|
||||
use Modules\Testimonials\Models\Testimonial;
|
||||
use Throwable;
|
||||
|
||||
final class FrontendContent
|
||||
{
|
||||
/** @return array<string, mixed> */
|
||||
public function homepage(array $settings): array
|
||||
{
|
||||
// Always provide source collections. Visibility is owned by page placements
|
||||
// in the composable content system; the legacy theme still applies its
|
||||
// existing show_* settings while no composition has been installed.
|
||||
return [
|
||||
'pricingPlans' => $this->pricingPlans(),
|
||||
'testimonials' => $this->testimonials(),
|
||||
'faqs' => $this->faqs(),
|
||||
'teamMembers' => $this->team(),
|
||||
'latestBlogPosts' => $this->blogPosts(),
|
||||
'latestNewsArticles' => $this->newsArticles(),
|
||||
];
|
||||
}
|
||||
|
||||
private function pricingPlans(): Collection
|
||||
{
|
||||
return $this->query('products', fn () => Product::query()
|
||||
->where('is_active', true)
|
||||
->where('product_type', 'plan')
|
||||
->orderBy('sort_order')
|
||||
->orderBy('id')
|
||||
->limit(6)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function testimonials(): Collection
|
||||
{
|
||||
return $this->query('testimonials', fn () => Testimonial::query()
|
||||
->where('enabled', true)
|
||||
->latest('id')
|
||||
->limit(6)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function faqs(): Collection
|
||||
{
|
||||
return $this->query('faqs', fn () => Faq::query()
|
||||
->where('enabled', true)
|
||||
->orderBy('sort_order')
|
||||
->limit(12)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function team(): Collection
|
||||
{
|
||||
return $this->query('team_members', fn () => TeamMember::query()
|
||||
->where('enabled', true)
|
||||
->orderBy('sort_order')
|
||||
->limit(8)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function blogPosts(): Collection
|
||||
{
|
||||
return $this->query('blog_posts', fn () => Blog::query()
|
||||
->published()
|
||||
->latest('published_at')
|
||||
->limit(3)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function newsArticles(): Collection
|
||||
{
|
||||
return $this->query('news_articles', fn () => News::query()
|
||||
->published()
|
||||
->latest('published_at')
|
||||
->limit(3)
|
||||
->get());
|
||||
}
|
||||
|
||||
private function query(string $table, callable $callback): Collection
|
||||
{
|
||||
try {
|
||||
return Schema::hasTable($table) ? $callback() : collect();
|
||||
} catch (Throwable) {
|
||||
return collect();
|
||||
}
|
||||
}
|
||||
|
||||
private function enabled(array $settings, string $key, bool $default): bool
|
||||
{
|
||||
return filter_var($settings[$key] ?? $default, FILTER_VALIDATE_BOOL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user