Skip to content

Commit 582d854

Browse files
committed
Fixed bug with composer install post dump autoload when database not connected yet
1 parent 8314b46 commit 582d854

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/LaravelCrmServiceProvider.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Illuminate\Support\Collection;
1212
use Illuminate\Support\Facades\Gate;
1313
use Illuminate\Support\Facades\Route;
14-
use Illuminate\Support\Facades\Schema;
1514
use Illuminate\Support\ServiceProvider;
1615
use Livewire\Livewire;
1716
use VentureDrake\LaravelCrm\Console\LaravelCrmAddressTypes;
@@ -134,6 +133,7 @@
134133
use VentureDrake\LaravelCrm\Observers\XeroItemObserver;
135134
use VentureDrake\LaravelCrm\Observers\XeroPersonObserver;
136135
use VentureDrake\LaravelCrm\Observers\XeroTokenObserver;
136+
use VentureDrake\LaravelCrm\View\Composers\SettingsComposer;
137137

138138
class LaravelCrmServiceProvider extends ServiceProvider
139139
{
@@ -479,13 +479,9 @@ function ($perPage = 30, $page = null, $options = []) {
479479
});
480480
}
481481

482-
if (Schema::hasTable(config('laravel-crm.db_table_prefix').'settings')) {
483-
view()->share('dateFormat', Setting::where('name', 'date_format')->first()->value ?? 'Y/m/d');
484-
view()->share('timeFormat', Setting::where('name', 'time_format')->first()->value ?? 'H:i');
485-
} else {
486-
view()->share('dateFormat', 'Y/m/d');
487-
view()->share('timeFormat', 'H:i');
488-
}
482+
view()->composer('laravel-crm::layouts.app', SettingsComposer::class);
483+
view()->composer('laravel-crm::layouts.document', SettingsComposer::class);
484+
view()->composer('laravel-crm::layouts.portal', SettingsComposer::class);
489485
}
490486

491487
/**

src/Traits/HasGlobalSettings.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ trait HasGlobalSettings
88
{
99
public static function dateFormat()
1010
{
11-
if(\DB::connection()->getPDO()){
12-
return Setting::where('name', 'date_format')->first()->value ?? 'Y/m/d';
13-
}
11+
return Setting::where('name', 'date_format')->first()->value ?? 'Y/m/d';
1412
}
1513

1614
public static function timeFormat()
1715
{
18-
if(\DB::connection()->getPDO()) {
19-
return Setting::where('name', 'time_format')->first()->value ?? 'H:i';
20-
}
16+
return Setting::where('name', 'time_format')->first()->value ?? 'H:i';
2117
}
2218
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\View\Composers;
4+
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\View\View;
7+
use VentureDrake\LaravelCrm\Models\Setting;
8+
9+
class SettingsComposer
10+
{
11+
public function compose(View $view)
12+
{
13+
if (Schema::hasTable(config('laravel-crm.db_table_prefix').'settings')) {
14+
$view->with('dateFormat', Setting::where('name', 'date_format')->first()->value ?? 'Y/m/d');
15+
$view->with('timeFormat', Setting::where('name', 'time_format')->first()->value ?? 'H:i');
16+
} else {
17+
$view->with('dateFormat', 'Y/m/d');
18+
$view->with('timeFormat', 'H:i');
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)