Skip to content

Commit cc31249

Browse files
committed
bugfix for 'Filament\Support\Commands\Concerns\CanValidateInput' not found
1 parent 1d43047 commit cc31249

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/Commands/MakeTreePageCommand.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
namespace SolutionForest\FilamentTree\Commands;
44

5+
use Closure;
56
use Filament\Support\Commands\Concerns\CanManipulateFiles;
6-
use Filament\Support\Commands\Concerns\CanValidateInput;
77
use Illuminate\Console\Command;
8+
use Illuminate\Support\Facades\Validator;
89
use Illuminate\Support\Str;
910

1011
class MakeTreePageCommand extends Command
1112
{
1213
use CanManipulateFiles;
13-
use CanValidateInput;
14+
1415
protected $signature = "make:filament-tree-page {name?} {--model=} {--R|resource=} {--F|force}";
1516

1617
public $description = 'Creates a Filament tree page class';
@@ -124,4 +125,30 @@ protected function askResourceClass(): void
124125
->afterLast('\\');
125126
}
126127
}
128+
protected function askRequired(string $question, string $field, ?string $default = null): string
129+
{
130+
return $this->validateInput(fn () => $this->ask($question, $default), $field, ['required']);
131+
}
132+
133+
protected function validateInput(Closure $callback, string $field, array $rules, ?Closure $onError = null): string
134+
{
135+
$input = $callback();
136+
137+
$validator = Validator::make(
138+
[$field => $input],
139+
[$field => $rules],
140+
);
141+
142+
if ($validator->fails()) {
143+
$this->error($validator->errors()->first());
144+
145+
if ($onError) {
146+
$onError($validator);
147+
}
148+
149+
$input = $this->validateInput($callback, $field, $rules);
150+
}
151+
152+
return $input;
153+
}
127154
}

src/Commands/MakeTreeWidgetCommand.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace SolutionForest\FilamentTree\Commands;
44

5+
use Closure;
56
use Filament\Support\Commands\Concerns\CanManipulateFiles;
67
use Filament\Support\Commands\Concerns\CanValidateInput;
78
use Illuminate\Console\Command;
8-
use Illuminate\Support\Facades\Artisan;
9+
use Illuminate\Support\Facades\Validator;
910
use Illuminate\Support\Str;
1011

1112
class MakeTreeWidgetCommand extends Command
@@ -90,4 +91,31 @@ public function handle(): int
9091

9192
return static::SUCCESS;
9293
}
94+
95+
protected function askRequired(string $question, string $field, ?string $default = null): string
96+
{
97+
return $this->validateInput(fn () => $this->ask($question, $default), $field, ['required']);
98+
}
99+
100+
protected function validateInput(Closure $callback, string $field, array $rules, ?Closure $onError = null): string
101+
{
102+
$input = $callback();
103+
104+
$validator = Validator::make(
105+
[$field => $input],
106+
[$field => $rules],
107+
);
108+
109+
if ($validator->fails()) {
110+
$this->error($validator->errors()->first());
111+
112+
if ($onError) {
113+
$onError($validator);
114+
}
115+
116+
$input = $this->validateInput($callback, $field, $rules);
117+
}
118+
119+
return $input;
120+
}
93121
}

0 commit comments

Comments
 (0)