-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakeView.php
More file actions
42 lines (33 loc) · 1.38 KB
/
Copy pathMakeView.php
File metadata and controls
42 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Aerni\LivewireForms\Commands;
use Aerni\LivewireForms\Facades\ViewManager;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Path;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\text;
class MakeView extends Command
{
use RunsInPlease;
protected $signature = 'livewire-forms:view {name?}';
protected $description = 'Create a new Livewire Forms view';
public function handle(): void
{
$name = $this->argument('name') ?? text(label: 'What do you want to name the view?', default: config('livewire-forms.view'), required: true);
$stub = File::get(__DIR__.'/../../resources/views/default.blade.php');
$filename = Str::slug($name).'.blade.php';
$path = ViewManager::absoluteViewPath($filename);
if (! File::exists($path) || confirm(label: 'A view with this name already exists. Do you want to overwrite it?', default: false)) {
File::ensureDirectoryExists(ViewManager::absoluteViewPath());
File::put($path, $stub);
info("The view was successfully created: <comment>{$this->getRelativePath($path)}</comment>");
}
}
protected function getRelativePath($path): string
{
return Path::makeRelative($path);
}
}