54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\NavbarManager\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Paymenter\Extensions\Others\NavbarManager\Helpers\NavbarHelper;
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
{
|
|
public function boot()
|
|
{
|
|
// Always load migrations regardless of context
|
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
|
|
|
|
// Only register views and components if not in admin context
|
|
if (!$this->isAdminContext()) {
|
|
// Register view namespace
|
|
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'navbar-manager');
|
|
|
|
// Register Blade components
|
|
Blade::componentNamespace('Paymenter\\Extensions\\Others\\NavbarManager\\View\\Components', 'navbar-manager');
|
|
|
|
// Register global Blade directive for easy navbar usage
|
|
Blade::directive('navbarManagerLinks', function ($expression) {
|
|
return "<?php echo \Paymenter\Extensions\Others\NavbarManager\Helpers\NavbarHelper::render($expression); ?>";
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if we're in admin context
|
|
*/
|
|
private function isAdminContext(): bool
|
|
{
|
|
if (app()->runningInConsole()) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
$currentPath = request()->path();
|
|
|
|
return str_starts_with($currentPath, 'admin') ||
|
|
str_contains($currentPath, '/admin/') ||
|
|
str_starts_with($currentPath, 'filament') ||
|
|
request()->is('admin') ||
|
|
request()->is('admin/*') ||
|
|
request()->is('filament/*');
|
|
} catch (\Exception $e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|