Files
aroginhealthcare/app/Providers/AppServiceProvider.php
2025-08-17 16:23:14 +05:45

200 lines
5.9 KiB
PHP

<?php
namespace App\Providers;
use Modules\Blog\app\Models\Blog;
use Modules\Page\app\Models\Page;
use Modules\Post\app\Models\Post;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Modules\Service\app\Models\Service;
use Modules\Setting\app\Models\Setting;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Schema::defaultStringLength(191);
$this->getSeoSetting();
$this->getGeneralSetting();
$this->getAdditionalSetting();
//-- Social media
$this->socialMediaShare();
//-- Social media
//-- Blog
$this->blog();
//-- Site Logo
$this->getSiteImage();
$this->getMultipleSiteImage();
$this->getHairPosts();
$this->getAllServices();
$this->getExtraPages();
}
public function getSeoSetting()
{
if (Schema::hasTable('settings')) {
$seoSettings = Setting::where('setting_name', 'seo_setting')->get();
if ($seoSettings->isNotEmpty()) {
$settings = [];
foreach ($seoSettings as $setting) {
$settings[$setting->name] = $setting->detail;
}
view()->share('seoSetting', $settings);
}
}
}
public function getGeneralSetting()
{
if (Schema::hasTable('settings')) {
$generalSettings = Setting::where('setting_name', 'general_setting')->get();
if ($generalSettings->isNotEmpty()) {
$settings = [];
foreach ($generalSettings as $setting) {
$settings[$setting->name] = $setting->detail;
}
view()->share('generalSetting', $settings);
}
}
}
public function getAdditionalSetting()
{
if (Schema::hasTable('settings')) {
$additionalSettings = Setting::where('setting_name', 'additional_setting')->get();
if ($additionalSettings->isNotEmpty()) {
$settings = [];
foreach ($additionalSettings as $setting) {
$settings[$setting->name] = $setting->detail;
}
view()->share('additionalSetting', $settings);
}
}
}
//-- Social media share
public function socialMediaShare()
{
if (Schema::hasTable('settings')) {
$socialMediaShares = Setting::where('setting_name', 'social_setting')->get();
if ($socialMediaShares->isNotEmpty()) {
view()->share('socialMediaShareKey', compact('socialMediaShares'));
}
}
}
//-- Social media share
//-- Blog
public function blog()
{
if (Schema::hasTable('blogs')) {
$blogs = Blog::latest()->take(3)->get();
if ($blogs->isNotEmpty()) {
view()->share('blogkey', compact('blogs'));
}
}
}
//-- Get site logo for backend
public function getSiteImage()
{
View::composer('admin::layouts.master', function ($view) {
$siteLogoSetting = Setting::where('setting_name', 'general_setting')
->whereIn('name', ['primary_image', 'secondary_image'])
->orderBy('id', 'ASC')
->get();
if ($siteLogoSetting->isNotEmpty()) {
$imageSetting = $siteLogoSetting->where('name', 'primary_image')->first();
if (is_null($imageSetting) || is_null($imageSetting->detail) || empty($imageSetting->detail)) {
$imageSetting = $siteLogoSetting->where('name', 'secondary_image')->first();
}
$siteLogo = asset('storage/uploads/' . optional($imageSetting)->detail);
} else {
$siteLogo = asset('backend/uploads/site_logo/defaultLogo.png');
}
$view->with('siteLogo', $siteLogo);
});
}
//-- Get site logo for Frontend
public function getMultipleSiteImage()
{
View::composer(
// 'frontend.layouts.partials.header',
'frontend.layouts.main',
function ($view) {
$view->with('primaryLogo', $this->getSiteLogo('primary_image'));
$view->with('secondaryLogo', $this->getSiteLogo('secondary_image'));
}
);
}
public function getSiteLogo($imageName)
{
$siteLogoSetting = Setting::where('setting_name', 'general_setting')
->whereIn('name', [$imageName])
->first();
if ($siteLogoSetting && is_null($siteLogoSetting->detail) || empty($siteLogoSetting->detail)) {
return asset('backend/uploads/site_logo/defaultLogo.png');
} else {
return asset('storage/uploads/' . $siteLogoSetting->detail);
}
}
public function getHairPosts()
{
if (Schema::hasTable('posts')) {
$posts = Post::where('navbar_flag', '11')->orderBy('order', 'asc')->get();
if ($posts->isNotEmpty()) {
view()->share('hairPosts', $posts);
}
}
}
public function getAllServices()
{
if (Schema::hasTable('services')) {
$services = Service::where('status', 'active')->get();
if ($services->isNotEmpty()) {
view()->share('services', $services);
}
}
}
public function getExtraPages()
{
if (Schema::hasTable('pages')) {
$models = Page::where('code', 'normal')->where('status', 'active')->get();
if ($models->isNotEmpty()) {
view()->share('extraPages', $models);
}
}
}
}