// Update HomeController to use the same method as admin:
public function index()
{
try {
// Check Database access
AdminSettings::select('id')->first();
} catch (\Exception $e) {
// Redirect to Installer
return redirect('installer/script');
}
$categories = Categories::select(['name', 'slug', 'thumbnail'])->where('mode', 'on')->orderBy('name')->simplePaginate(4);
// Use the same method as admin - Eloquent models with relationships
$images = Images::with(['user'])
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$featured = Images::with(['user'])
->whereHas('featuredGallery', function($query) {
$query->where('status', 'active');
})
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$popularCategories = Categories::withCount('images')
->latest('images_count')
->has('images')->take(5)
->get();
if ($popularCategories->count() != 0) {
foreach ($popularCategories as $popularCategorie) {
$categoryName = Lang::has('categories.' . $popularCategorie->slug) ? __('categories.' . $popularCategorie->slug) : $popularCategorie->name;
$popularCategorieArray[] = '' . $categoryName . '';
}
$categoryPopular = implode(', ', $popularCategorieArray);
} else {
$categoryPopular = false;
}
return view(
'index.home',
[
'categories' => $categories,
'images' => $images,
'featured' => $featured,
'categoryPopular' => $categoryPopular
]
);
}// Update HomeController to use the same method as admin:
public function index()
{
try {
// Check Database access
AdminSettings::select('id')->first();
} catch (\Exception $e) {
// Redirect to Installer
return redirect('installer/script');
}
$categories = Categories::select(['name', 'slug', 'thumbnail'])->where('mode', 'on')->orderBy('name')->simplePaginate(4);
// Use the same method as admin - Eloquent models with relationships
$images = Images::with(['user'])
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$featured = Images::with(['user'])
->whereHas('featuredGallery', function($query) {
$query->where('status', 'active');
})
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$popularCategories = Categories::withCount('images')
->latest('images_count')
->has('images')->take(5)
->get();
if ($popularCategories->count() != 0) {
foreach ($popularCategories as $popularCategorie) {
$categoryName = Lang::has('categories.' . $popularCategorie->slug) ? __('categories.' . $popularCategorie->slug) : $popularCategorie->name;
$popularCategorieArray[] = '' . $categoryName . '';
}
$categoryPopular = implode(', ', $popularCategorieArray);
} else {
$categoryPopular = false;
}
return view(
'index.home',
[
'categories' => $categories,
'images' => $images,
'featured' => $featured,
'categoryPopular' => $categoryPopular
]
);
}// Update HomeController to use the same method as admin:
public function index()
{
try {
// Check Database access
AdminSettings::select('id')->first();
} catch (\Exception $e) {
// Redirect to Installer
return redirect('installer/script');
}
$categories = Categories::select(['name', 'slug', 'thumbnail'])->where('mode', 'on')->orderBy('name')->simplePaginate(4);
// Use the same method as admin - Eloquent models with relationships
$images = Images::with(['user'])
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$featured = Images::with(['user'])
->whereHas('featuredGallery', function($query) {
$query->where('status', 'active');
})
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$popularCategories = Categories::withCount('images')
->latest('images_count')
->has('images')->take(5)
->get();
if ($popularCategories->count() != 0) {
foreach ($popularCategories as $popularCategorie) {
$categoryName = Lang::has('categories.' . $popularCategorie->slug) ? __('categories.' . $popularCategorie->slug) : $popularCategorie->name;
$popularCategorieArray[] = '' . $categoryName . '';
}
$categoryPopular = implode(', ', $popularCategorieArray);
} else {
$categoryPopular = false;
}
return view(
'index.home',
[
'categories' => $categories,
'images' => $images,
'featured' => $featured,
'categoryPopular' => $categoryPopular
]
);
}// Update HomeController to use the same method as admin:
public function index()
{
try {
// Check Database access
AdminSettings::select('id')->first();
} catch (\Exception $e) {
// Redirect to Installer
return redirect('installer/script');
}
$categories = Categories::select(['name', 'slug', 'thumbnail'])->where('mode', 'on')->orderBy('name')->simplePaginate(4);
// Use the same method as admin - Eloquent models with relationships
$images = Images::with(['user'])
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$featured = Images::with(['user'])
->whereHas('featuredGallery', function($query) {
$query->where('status', 'active');
})
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$popularCategories = Categories::withCount('images')
->latest('images_count')
->has('images')->take(5)
->get();
if ($popularCategories->count() != 0) {
foreach ($popularCategories as $popularCategorie) {
$categoryName = Lang::has('categories.' . $popularCategorie->slug) ? __('categories.' . $popularCategorie->slug) : $popularCategorie->name;
$popularCategorieArray[] = '' . $categoryName . '';
}
$categoryPopular = implode(', ', $popularCategorieArray);
} else {
$categoryPopular = false;
}
return view(
'index.home',
[
'categories' => $categories,
'images' => $images,
'featured' => $featured,
'categoryPopular' => $categoryPopular
]
);
}// Update HomeController to use the same method as admin:
public function index()
{
try {
// Check Database access
AdminSettings::select('id')->first();
} catch (\Exception $e) {
// Redirect to Installer
return redirect('installer/script');
}
$categories = Categories::select(['name', 'slug', 'thumbnail'])->where('mode', 'on')->orderBy('name')->simplePaginate(4);
// Use the same method as admin - Eloquent models with relationships
$images = Images::with(['user'])
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$featured = Images::with(['user'])
->whereHas('featuredGallery', function($query) {
$query->where('status', 'active');
})
->where('status', 'active')
->orderBy('created_at', 'desc')
->take(20)
->get();
$popularCategories = Categories::withCount('images')
->latest('images_count')
->has('images')->take(5)
->get();
if ($popularCategories->count() != 0) {
foreach ($popularCategories as $popularCategorie) {
$categoryName = Lang::has('categories.' . $popularCategorie->slug) ? __('categories.' . $popularCategorie->slug) : $popularCategorie->name;
$popularCategorieArray[] = '' . $categoryName . '';
}
$categoryPopular = implode(', ', $popularCategorieArray);
} else {
$categoryPopular = false;
}
return view(
'index.home',
[
'categories' => $categories,
'images' => $images,
'featured' => $featured,
'categoryPopular' => $categoryPopular
]
);
}