Skip to content

Commit

Permalink
Merge pull request #3 from alielzahaby74/master
Browse files Browse the repository at this point in the history
solving path variable and filament not installed error
  • Loading branch information
lordjoo authored Apr 2, 2023
2 parents e3b91c4 + 18f1779 commit e8ee5ef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
17 changes: 12 additions & 5 deletions src/LaraModularServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ class LaraModularServiceProvider extends ServiceProvider
*/
private mixed $modules_namespace;
private array $modules;

private array $commands;
public function register()
{
$this->commands = $this->getCommands();
// merge config
$this->mergeConfigFrom(
__DIR__ . '/laramodular.php', 'laramodular'
);
// register console command
$this->commands([
MakeModuleCommand::class,
MakeFilamentResourceCommand::class,
]);
$this->commands($this->commands);
// publish config
$this->publishes([
__DIR__ . '/laramodular.php' => config_path('laramodular.php'),
Expand Down Expand Up @@ -182,6 +180,15 @@ protected function registerMiddleware(Router $router, $config, $module)
// }
}

public function getCommands() : array
{
$commands = [MakeModuleCommand::class];
if(class_exists("Filament\Commands\MakeResourceCommand")) {
array_push($commands, MakeFilamentResourceCommand::class);
}
return $commands;
}



}
27 changes: 19 additions & 8 deletions src/MakeFilamentResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Filament\Support\Commands\Concerns;
use Filament\Commands\MakeResourceCommand;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use ReflectionClass;

Expand Down Expand Up @@ -48,6 +49,17 @@ public function handle(): int
$this->call('make:module', ['name' => $this->module_name]);
}

if (!is_dir(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name)) {
$this->components->warn("Module {$this->module_name} does not exists!");
$this->call('make:module', ['name' => $this->module_name]);
}
// dd(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name .
// DIRECTORY_SEPARATOR . "Filament/Resources");
if(!is_dir(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name . DIRECTORY_SEPARATOR . "Filament/Resources"))
{
File::makeDirectory(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name .
DIRECTORY_SEPARATOR . "Filament/Resources", 7777,true);
}
$resource = "{$model}Resource";
$resourceClass = "{$modelClass}Resource";
$resourceNamespace = $modelNamespace;
Expand All @@ -61,10 +73,10 @@ public function handle(): int
$baseResourcePath = $this->getBaseResourcePath($resource);

$this->namespace = $this->getNamespace($resource);

// dd($this->namespace);

$resourcePath = "{$baseResourcePath}.php";
// dd($resourcePath);
$resourcePagesDirectory = "{$baseResourcePath}/Pages";
$listResourcePagePath = "{$resourcePagesDirectory}/{$this->listResourcePageClass}.php";
$manageResourcePagePath = "{$resourcePagesDirectory}/{$this->manageResourcePageClass}.php";
Expand Down Expand Up @@ -205,13 +217,12 @@ public function getModelNamespace($model)
}

public function getBaseResourcePath($resource)
{
$module = config('laramodular.modules_path').'\\'.$this->module_name;
return base_path(
(string) Str::of($resource)
->prepend($module.'\\Filament\\Resources\\')
->replace('\\', '/')->replace(base_path(), ''),
);
{ //E:/work/Backend/laravel/lordjooPackage/app/Modules/Categories/Filament/Resources/CategoriesResource
$module = config('laramodular.modules_path').'\\'.$this->module_name; //E:\work\Backend\laravel\lordjooPackage\app/Modules\Categories (module)
return (string) Str::of($module)
->append('\\Filament\\Resources\\'.$resource)
->replace('\\', '/');

}

public function pagesCode()
Expand Down
2 changes: 1 addition & 1 deletion src/MakeModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function makeServiceProviderFile()
$stub = file_get_contents(__DIR__ . '/moduleServiceProvider.stub');
$stub = str_replace('{{moduleName}}', $this->module_name, $stub);
$stub = str_replace('{{namespace}}', $this->module_namespace, $stub);

file_put_contents($this->module_path . DIRECTORY_SEPARATOR . $this->module_name . 'ModuleServiceProvider.php', $stub);
}

Expand Down

0 comments on commit e8ee5ef

Please sign in to comment.