Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget Command Livewire Path Solution #15871

Closed
wants to merge 7 commits into from
Closed

Conversation

ksaif534
Copy link

Hello.

This is a solution to this Github issue: https://github.com/filamentphp/filament/issues/14637

Description

When the make:filament-widget command is run to create a new widget and the resource is provided and when the user selects [App\Livewire] alongside other Livewire components after selecting Table from the first prompt, a file permission error was thrown and the directory was not being created. The solution now creates a new file TestWidget.php within the app/Livewire directory when it's prompted by the user.

Visual Changes

After the Solution:

widget-command-livewire-solution

Before the Solution:

widget-command-livewire-solution-before

Functional Changes

I've fixed the style with the composer cs command, the file changes have been tested.

@danharrin danharrin added this to the v3 milestone Mar 18, 2025
@danharrin danharrin added the bug Something isn't working label Mar 18, 2025
@fathurrohman26
Copy link

fathurrohman26 commented Mar 18, 2025

Hi @ksaif534, I have tried the solution you provided, but it seems the generated namespace is not correct.

@ksaif534 ** ksaif534**

❯ php artisan make:filament-widget PaymentChart --chart --resource=PaymentResource

 ┌ Where would you like to create this? ────────────────────────┐
 │ [App\Livewire] alongside other Livewire components           │
 └──────────────────────────────────────────────────────────────┘

 ┌ Which type of chart would you like to create? ───────────────┐
 │ Bar chart                                                    │
 └──────────────────────────────────────────────────────────────┘

   INFO  Filament widget [app/Livewire/PaymentChart.php] created successfully.

   INFO  Make sure to register the widget in `PaymentResource::getWidgets()`, and then again in `getHeaderWidgets()` or `getFooterWidgets()` of any `PaymentResource` page.
❯ bat app/Livewire/PaymentChart.php
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: app/Livewire/PaymentChart.php
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <?php
   2   │
   3   │ namespace \PaymentResource\Widgets;
   4   │
   5   │ use Filament\Widgets\ChartWidget;
   6   │
   7   │ class PaymentChart extends ChartWidget
   8   │ {
   9   │     protected static ?string $heading = 'Chart';
  10   │
  11   │     protected function getData(): array
  12   │     {
  13   │         return [
  14   │             //
  15   │         ];
  16   │     }
  17   │
  18   │     protected function getType(): string
  19   │     {
  20   │         return 'bar';
  21   │     }
  22   │ }
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

@ksaif534
Copy link
Author

@fathurrohman26 Oh, I didn't notice that. I'll try to fix it.

@danharrin
Copy link
Member

I did remove the test since there is a new style of tests in v4 and this would not work being merged in to that

@ksaif534
Copy link
Author

@fathurrohman26 @danharrin I've adjusted the changes and fixed the problems in the initial solution. It'd be great if you can provide feedback.

Adjusted PR: #15910

@danharrin danharrin closed this Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants