Skip to content

Commit

Permalink
Add exception for runningInConsole in FilamentFabricatorServiceProvid…
Browse files Browse the repository at this point in the history
…er.php

I've encountered an issue with the `Z3d0X/filament-fabricator` package in Laravel, related to using models directly within Block files. The problem arises when these models are loaded from a ServiceProvider. This becomes evident during a fresh migration process, where the error "table not exists" is thrown because the system attempts to access the table while it is being migrated.
  • Loading branch information
yolanmees authored May 23, 2024
1 parent 0b1a47a commit 5d3df2d
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/FilamentFabricatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,35 @@ public function packageRegistered(): void

public function bootingPackage(): void
{
Route::bind('filamentFabricatorPage', function ($value) {
$pageModel = FilamentFabricator::getPageModel();

$pageUrls = FilamentFabricator::getPageUrls();

$value = Str::start($value, '/');

$pageId = array_search($value, $pageUrls);

return $pageModel::query()
->where('id', $pageId)
->firstOrFail();
});

$this->registerComponentsFromDirectory(
Layout::class,
config('filament-fabricator.layouts.register'),
config('filament-fabricator.layouts.path'),
config('filament-fabricator.layouts.namespace')
);

$this->registerComponentsFromDirectory(
PageBlock::class,
config('filament-fabricator.page-blocks.register'),
config('filament-fabricator.page-blocks.path'),
config('filament-fabricator.page-blocks.namespace')
);
if (! $this->app->runningInConsole()) {
Route::bind('filamentFabricatorPage', function ($value) {
$pageModel = FilamentFabricator::getPageModel();

$pageUrls = FilamentFabricator::getPageUrls();

$value = Str::start($value, '/');

$pageId = array_search($value, $pageUrls);

return $pageModel::query()
->where('id', $pageId)
->firstOrFail();
});

$this->registerComponentsFromDirectory(
Layout::class,
config('filament-fabricator.layouts.register'),
config('filament-fabricator.layouts.path'),
config('filament-fabricator.layouts.namespace')
);

$this->registerComponentsFromDirectory(
PageBlock::class,
config('filament-fabricator.page-blocks.register'),
config('filament-fabricator.page-blocks.path'),
config('filament-fabricator.page-blocks.namespace')
);
}
}

protected function registerComponentsFromDirectory(string $baseClass, array $register, ?string $directory, ?string $namespace): void
Expand Down

0 comments on commit 5d3df2d

Please sign in to comment.