JibayMcs / filament-tour

Let's embed the power of DriverJS to your filament admin panel, and guide peoples through your app
MIT License
99 stars 28 forks source link

[Bug]: EditRecord - Missing required parameter #20

Open S8N02000 opened 3 months ago

S8N02000 commented 3 months ago

What happened?

Error Encountered:

Missing required parameter for [Route: filament.admin.resources.user-groups.edit] [URI: user-groups/{record}/edit] [Missing parameter: record].

This error occurs when I add a Tour or Highlight to an EditRecord. The issue does not occur with ListRecords or CreateRecord, which work as expected.

How to reproduce the bug

Error Description:

When adding HasTour and/or HasHighlight to the EditRecord page and including at least one Tour::make('xxxx') or Highlight::make('.fi-avatar'), every page—including those without the HasTour or HasHighlight—generates the following error message:

Missing required parameter for [Route: filament.admin.resources.user-groups.edit] [URI: user-groups/{record}/edit] [Missing parameter: record].

This issue arises despite ListRecords and CreateRecord functioning correctly with similar configurations.

Code Example:

<?php

namespace Modules\UserGroups\Filament\Resources\UserGroupsResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use JibayMcs\FilamentTour\Tour\HasTour;
use JibayMcs\FilamentTour\Tour\Step;
use JibayMcs\FilamentTour\Tour\Tour;
use Modules\UserGroups\Filament\Resources\UserGroupsResource;

class EditUserGroups extends EditRecord {

    use HasTour;

    protected static string $resource = UserGroupsResource::class;

    public function tours(): array {
        return [
            Tour::make('user-groups-edit')
                ->steps(
                    Step::make()
                        ->title("Welcome to your Dashboard !")
                        ->description("fgff"),

                    Step::make('.fi-avatar')
                        ->title('Woaw ! Here is your avatar !')
                        ->description('You look nice !')
                        ->icon('heroicon-o-user-circle')
                        ->iconColor('primary')
                ),
        ];
    }

    protected function getHeaderActions(): array {
        return [
            Actions\DeleteAction::make(),
        ];
    }
}

Here is the code for a ListRecords page that works correctly:


<?php

namespace Modules\UserGroups\Filament\Resources\UserGroupsResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use JibayMcs\FilamentTour\Highlight\HasHighlight;
use JibayMcs\FilamentTour\Highlight\Highlight;
use JibayMcs\FilamentTour\Tour\HasTour;
use JibayMcs\FilamentTour\Tour\Step;
use JibayMcs\FilamentTour\Tour\Tour;
use Modules\UserGroups\Filament\Resources\UserGroupsResource;

class ListUserGroups extends ListRecords {

    use HasTour;
    use HasHighlight;

    protected static string $resource = UserGroupsResource::class;

    public function highlights(): array {

        return [

            Highlight::make('.fi-header-heading')
                     ->element('.fi-header-heading')
                     ->title('Whoaw ! You highlighted the title of the page !')
                     ->description('"Dashboard"'),

            Highlight::make('.fi-avatar')
                     ->element('.fi-avatar')
                     ->title("Pssst ! That's your avatar")
                     ->icon('heroicon-o-user-circle')
                     ->iconColor('primary'),

        ];
    }

    public function tours(): array {

        return [
            Tour::make('user-groups-list')
                ->steps(

                    Step::make()
                        ->title("Welcome to your Dashboard !")
                        ->description("fgff"),

                    Step::make('.fi-avatar')
                        ->title('Woaw ! Here is your avatar !')
                        ->description('You look nice !')
                        ->icon('heroicon-o-user-circle')
                        ->iconColor('primary')
                ),
        ];
    }

    protected function getHeaderActions(): array {

        return [
            Actions\CreateAction::make(),
        ];
    }
}

Package Version

3.1

PHP Version

8.3.9

Laravel Version

11.15.0

Which operating systems does with happen with?

Linux

Notes

If the tours() or highlights() function returns an empty array, no error is generated.

Thanks for your plugin !

thomas-alrek commented 3 months ago

+1 I'm also encountering this issue

JonathanVorich commented 2 weeks ago

I use a workaround till this bug gets fixed. you need to adjust the explode key for your route

public function tours(): array
    {
        $recordId = isset(explode('/', parse_url(url()->previous())['path'])[3]) ? explode('/', parse_url(url()->previous())['path'])[3] : null;
        return [
            Tour::make('example_create')
                ->steps(
                    Step::make()
                        ->title('Example title')
                        ->description('Example description, lorem ipsum ...'),
                )
                //can be removed after bug is fixed https://github.com/JibayMcs/filament-tour/issues/20
                ->route('/app/examples/'.$recordId.'/edit'),
        ];
    }