• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / filament-user-attributes / 6917010354

18 Nov 2023 11:58PM UTC coverage: 76.475% (+13.3%) from 63.165%
6917010354

push

github

luttje
Merge branch 'main' of https://github.com/luttje/filament-user-attributes

1141 of 1492 relevant lines covered (76.47%)

28.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.94
/src/Commands/WizardStepConfig.php
1
<?php
2

3
namespace Luttje\FilamentUserAttributes\Commands;
4

5
use Illuminate\Console\Command;
6
use Luttje\FilamentUserAttributes\CodeGeneration\CodeEditor;
7
use Luttje\FilamentUserAttributes\Contracts\ConfiguresUserAttributesContract;
8
use Luttje\FilamentUserAttributes\Facades\FilamentUserAttributes;
9
use Luttje\FilamentUserAttributes\Traits\ConfiguresUserAttributes;
10

11
class WizardStepConfig extends Command
12
{
13
    public function __construct()
4✔
14
    {
15
        $this->signature = 'filament-user-attributes:wizard-config';
4✔
16
        $this->description = 'Wizard to help setup your config model with Filament User Attributes';
4✔
17

18
        parent::__construct();
4✔
19
    }
20

21
    public function handle()
4✔
22
    {
23
        if (!$this->promptForConfigSetup()) {
4✔
24
            return;
4✔
25
        }
26

27
        $this->finalizeConfigSetup();
×
28
    }
29

30
    protected function promptForConfigSetup(): bool
4✔
31
    {
32
        $this->listConfigurableModels();
4✔
33

34
        return $this->confirm(
4✔
35
            "Do you want to let a model (like user or tenant) configure user attributes?",
4✔
36
            true
4✔
37
        );
4✔
38
    }
39

40
    protected function finalizeConfigSetup(): void
×
41
    {
42
        $model = $this->selectModelForConfig("Which model should configure user attributes?");
×
43
        $this->setupConfigModel($model);
×
44
    }
45

46
    private function listConfigurableModels(): void
4✔
47
    {
48
        $this->line('The following models are setup to support user attributes:');
4✔
49

50
        // Disable auto loading the models by setting configured to false
51
        collect(FilamentUserAttributes::getConfigurableModels(configuredOnly: false))
4✔
52
            ->filter(fn ($model) => WizardStepModels::isModelSetup($model))
4✔
53
            ->each(fn ($model) => $this->line("- $model"));
4✔
54
    }
55

56
    private function selectModelForConfig(string $prompt): string
×
57
    {
58
        $models = FilamentUserAttributes::getConfigurableModels(configuredOnly: false);
×
59
        $choice = $this->choice($prompt, $models);
×
60
        return $choice;
×
61
    }
62

63
    protected function setupConfigModel(string $model): void
×
64
    {
65
        $file = FilamentUserAttributes::findModelFilePath($model);
×
66

67
        $editor = CodeEditor::make();
×
68
        $editor->editFileWithBackup($file, function ($code) use ($editor) {
×
69
            $code = $editor->addTrait($code, ConfiguresUserAttributes::class);
×
70
            $code = $editor->addInterface($code, ConfiguresUserAttributesContract::class);
×
71
            return $code;
×
72
        });
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc