add new command for creating fieldsets

This commit is contained in:
Ryan Scherler
2020-04-05 20:10:20 -07:00
parent cad285c6fc
commit ab1f7bf89e
9 changed files with 78 additions and 16 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Filament\Http\Fieldsets;
use Filament\Contracts\Fieldset;
use Filament\Support\Fields\Field;
class DummyFieldset implements Fieldset
{
public static function title(): string
{
return 'Dummy';
}
public static function fields($model): array
{
return [
Field::make('Name')
->input()
->rules(['required', 'string', 'max:255']),
];
}
public static function rulesIgnoreRealtime(): array
{
return [];
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Filament\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class MakeFieldset extends Command
{
protected $signature = 'filament:fieldset {name} {--package}';
protected $description = 'Make a new Filament fieldset.';
public function handle()
{
$fieldsetName = Str::studly($this->argument('name')).'Fieldset';
$stub = File::get(__DIR__.'/../../resources/stubs/fieldset.stub');
$stub = str_replace('DummyFieldset', $fieldsetName, $stub);
$stub = str_replace('Dummy', $this->argument('name'), $stub);
if (!$this->option('package')) {
$stub = str_replace('namespace Filament', 'namespace App', $stub);
}
$fieldsetPath = $this->option('package') ? __DIR__.'/../Http/Fieldsets/' : app_path('Http/Fieldsets/');
$path = $fieldsetPath.$fieldsetName.'.php';
if (!File::exists($path) || $this->confirm($fieldsetName.' already exists. Overwrite it?')) {
File::put($path, $stub);
$this->info($fieldsetName.' was created in '. $fieldsetPath);
}
}
}
+6 -8
View File
@@ -6,8 +6,6 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Filament;
class MakeForm extends Command
{
protected $signature = 'filament:form {name} {--model=Model} {--package}';
@@ -17,9 +15,9 @@ class MakeForm extends Command
{
$componentName = Str::studly($this->argument('name'));
$stub = File::get(__DIR__ . '/../../resources/stubs/component.stub');
$stub = File::get(__DIR__.'/../../resources/stubs/component.stub');
$stub = str_replace('DummyComponent', $componentName, $stub);
$stub = str_replace('Contracts\Dummy', 'Contracts\\' . $this->option('model'), $stub);
$stub = str_replace('Contracts\Dummy', 'Contracts\\'.$this->option('model'), $stub);
$stub = str_replace('DummyClass', lcFirst($this->option('model')).'Class', $stub);
$stub = str_replace('DummyContract', $this->option('model').'Contract', $stub);
$stub = str_replace('DummyRoute', Str::slug(Str::plural($this->option('model'))), $stub);
@@ -29,12 +27,12 @@ class MakeForm extends Command
$stub = str_replace('namespace Filament', 'namespace App', $stub);
}
$formPath = $this->option('package') ? __DIR__ . '/../Http/Livewire/' : app_path('Http/Livewire/');
$path = $formPath . $componentName . '.php';
$formPath = $this->option('package') ? __DIR__.'/../Http/Livewire/' : app_path('Http/Livewire/');
$path = $formPath.$componentName.'.php';
if (!File::exists($path) || $this->confirm($componentName . ' already exists. Overwrite it?')) {
if (!File::exists($path) || $this->confirm($componentName.' already exists. Overwrite it?')) {
File::put($path, $stub);
$this->info($componentName . ' was created in '. $formPath);
$this->info($componentName.' was created in '. $formPath);
}
}
}
@@ -6,7 +6,7 @@ use Illuminate\Console\Command;
use Filament\Traits\ConsoleValidation;
use Filament\Contracts\User as UserContract;
class CreateUserCommand extends Command
class MakeUser extends Command
{
use ConsoleValidation;
+4 -2
View File
@@ -14,8 +14,9 @@ use Filament\Support\BladeDirectives;
use Filament\Contracts\User as UserContract;
use Filament\Traits\EventMap;
use Filament\Http\Middleware\Authenticate;
use Filament\Commands\CreateUserCommand;
use Filament\Commands\MakeUser;
use Filament\Commands\MakeForm;
use Filament\Commands\MakeFieldset;
class FilamentServiceProvider extends ServiceProvider
{
@@ -125,8 +126,9 @@ class FilamentServiceProvider extends ServiceProvider
{
if ($this->app->runningInConsole()) {
$this->commands([
CreateUserCommand::class,
MakeUser::class,
MakeForm::class,
MakeFieldset::class,
]);
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ class BladeDirectives {
*/
public static function pushOnce($expression)
{
$var = '$__env->{"__pushonce_" . md5(__FILE__ . ":" . __LINE__)}';
$var = '$__env->{"__pushonce_".md5(__FILE__.":".__LINE__)}';
return "<?php if (!isset({$var})): {$var} = true; \$__env->startPush({$expression}); ?>";
}
+1 -1
View File
@@ -168,6 +168,6 @@ class BaseField
public function getView()
{
return $this->view ?? 'filament::fields.' . $this->type;
return $this->view ?? 'filament::fields.'.$this->type;
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ class Field extends BaseField
{
$this->name = $name ?? Str::snake(Str::lower($label));
$this->label = __($label);
$this->key = $key_prefix ? 'form_data.' . $this->name : $this->name;
$this->key = $key_prefix ? 'form_data.'.$this->name : $this->name;
}
public static function make($label, $name = null, $key_prefix = true)
+2 -2
View File
@@ -63,7 +63,7 @@ trait HandlesFiles
$this->form_data[$field_name] = $value ?? [];
$this->saveField($field_name);
$this->updated('form_data.' . $field_name);
$this->updated('form_data.'.$field_name);
}
public function fileRemove($field_name, $file_name, $key)
@@ -79,7 +79,7 @@ trait HandlesFiles
$this->arrayRemove($field_name, $key);
$this->saveField($field_name);
$this->updated('form_data.' . $field_name);
$this->updated('form_data.'.$field_name);
}
public function fileInfo($mime_type)