first change
This commit is contained in:
268
app/Helpers/QueryHelper.php
Normal file
268
app/Helpers/QueryHelper.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
use Modules\CCMS\Models\Blog;
|
||||
use Modules\CCMS\Models\Category;
|
||||
use Modules\CCMS\Models\Counter;
|
||||
use Modules\CCMS\Models\Country;
|
||||
use Modules\CCMS\Models\Faq;
|
||||
use Modules\CCMS\Models\FaqCategory;
|
||||
use Modules\CCMS\Models\Gallery;
|
||||
use Modules\CCMS\Models\GalleryCategory;
|
||||
use Modules\CCMS\Models\Institution;
|
||||
use Modules\CCMS\Models\Page;
|
||||
use Modules\CCMS\Models\Partner;
|
||||
use Modules\CCMS\Models\Service;
|
||||
use Modules\CCMS\Models\Slider;
|
||||
use Modules\CCMS\Models\Team;
|
||||
use Modules\CCMS\Models\Test;
|
||||
use Modules\CCMS\Models\Testimonial;
|
||||
use Modules\Menu\Models\Menu;
|
||||
|
||||
function getSliders(?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
return Slider::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getBlogCategories(?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
return Category::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getFAQs(?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
return Faq::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getTeams(?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
return Team::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getTestimonials(?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
return Testimonial::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
function getPartners(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
|
||||
{
|
||||
$query = Partner::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order);
|
||||
|
||||
if ($limit && $paginate) {
|
||||
return $query->paginate($limit);
|
||||
} elseif ($limit && !$paginate) {
|
||||
return $query->limit($limit)->get();
|
||||
} else {
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
||||
function getGalleries(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
|
||||
{
|
||||
$query = Gallery::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order);
|
||||
|
||||
if ($limit && $paginate) {
|
||||
return $query->paginate($limit);
|
||||
} elseif ($limit && !$paginate) {
|
||||
return $query->limit($limit)->get();
|
||||
} else {
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
||||
function getBlogs(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
|
||||
{
|
||||
$query = Blog::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order);
|
||||
|
||||
if ($limit && $paginate) {
|
||||
return $query->paginate($limit);
|
||||
} elseif ($limit && !$paginate) {
|
||||
return $query->limit($limit)->get();
|
||||
} else {
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
||||
function getBlogBySlug(?string $slug)
|
||||
{
|
||||
return Blog::query()
|
||||
->where('status', 1)
|
||||
->where('slug', $slug)
|
||||
->first();
|
||||
}
|
||||
|
||||
function getCounters($limit = null, $order = 'desc')
|
||||
{
|
||||
return Counter::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getServices($limit = null, $order = 'desc')
|
||||
{
|
||||
return Service::query()
|
||||
->where('status', 1)
|
||||
->where('parent_id', null)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getInstitutions($limit = null, $order = 'desc')
|
||||
{
|
||||
return Institution::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getClasses($limit = null, $order = 'desc')
|
||||
{
|
||||
return Test::query()
|
||||
->where('status', 1)
|
||||
->where('parent_id', null)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getDestinations($limit = null, $order = 'desc')
|
||||
{
|
||||
return Country::query()
|
||||
->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
function getGalleriesByCategory(?int $limit = null, ?string $order = 'desc', ?string $category = null)
|
||||
{
|
||||
return GalleryCategory::query()
|
||||
->where('status', 1)
|
||||
->where('slug', $category)
|
||||
->with('galleries', function ($query) use ($limit, $order) {
|
||||
$query->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
});
|
||||
})
|
||||
->first();
|
||||
}
|
||||
|
||||
function getInstitutionsByCountry(?int $limit = null, ?string $order = 'desc', ?string $country = null)
|
||||
{
|
||||
return Country::query()
|
||||
->where('status', 1)
|
||||
->where('slug', $country)
|
||||
->with('institutions', function ($query) use ($limit, $order) {
|
||||
$query->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
});
|
||||
})
|
||||
->first();
|
||||
}
|
||||
|
||||
function getFAQsByCategory(?int $limit = null, ?string $order = 'desc', ?string $category = null)
|
||||
{
|
||||
return FaqCategory::query()
|
||||
->where('status', 1)
|
||||
->where('slug', $category)
|
||||
->with('faqs', function ($query) use ($limit, $order) {
|
||||
$query->where('status', 1)
|
||||
->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
});
|
||||
})
|
||||
->first();
|
||||
}
|
||||
|
||||
function getPageWithChildrenBySlug(?string $parent, ?string $slug, ?int $limit = null, ?string $order = 'desc')
|
||||
{
|
||||
$page = Page::where([
|
||||
'status' => 1,
|
||||
'type' => 'page',
|
||||
'slug' => $slug,
|
||||
])
|
||||
->when($parent, function ($query) use ($parent) {
|
||||
$query->where('parent', $parent);
|
||||
})
|
||||
->with(['children' => function ($query) use ($limit, $order) {
|
||||
$query->orderBy('order', $order)
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
$query->limit($limit);
|
||||
});
|
||||
}])
|
||||
->first();
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
function getAllHeaderMenusWithChildren()
|
||||
{
|
||||
$headerMenuItems = Menu::where(['menu_location_id' => 1, 'parent_id' => null, 'status' => 1])->with('children', function ($query) {
|
||||
$query->where('status', 1)
|
||||
->orderBy('order', 'asc');
|
||||
})->orderBy('order', 'asc')->get();
|
||||
return $headerMenuItems;
|
||||
}
|
||||
|
||||
function getAllFooterMenusWithChildren()
|
||||
{
|
||||
$footerMenuItems = Menu::where(['menu_location_id' => 2, 'parent_id' => null, 'status' => 1])->with('children', function ($query) {
|
||||
$query->orderBy('order', 'asc');
|
||||
})->orderBy('order', 'asc')->get();
|
||||
return $footerMenuItems;
|
||||
}
|
Reference in New Issue
Block a user