ycs77/laravel-wizard

Package does not play well with Laravel 8

rabol opened this issue · 4 comments

rabol commented

Use Version:
Use version when bugs appear.

  • Laravel: v8.27.0 (PHP v7.4.13)
  • Laravel Wizard: v2.3.0

Describe the bug
When trying to reach the url for a newly created wizard I get this:

Action UserRegistrationWizardController@create not defined

To Reproduce

php artisan make:wizard UserRegistration NameAndEmailStep,PlanSettngsSetp,BillingInfoStep

got to the url: test.test/wizard/user_registration

Expected behavior
no error, blank page

extra information:
I had to modify the route:

Wizard::routes('wizard/user', 'App\Http\Controllers\UserWizardController', 'wizard.user');
rabol commented

in the trait Wizadable.getActionUrl(), it looks like the return action() call hit's the wrong action method.

there is a action() in the

vendor/laravel/framework/src/Illuminate/Foundation/helpers.php

and there is one in

vendor/laravel//framework/src/Illuminate/Routing/UrlGenerator.php

and the last seems to be the one that is executed.

I did this change to the getActionUrl()

        $nameSpace = config('wizard.namespace.controllers');
        if(!Str::endsWith($nameSpace,'\\'))
            $nameSpace = Str::finish($nameSpace,'\\');

        return app('url')->action( $nameSpace . $method, $parameters, true);

it seems to work, but I'm not 100% sure if that is the best fix

@rabol Hey, seems that I also have reached this issue, however I had solved it in a slightly different way. I used trait nesting to resolve the method that caused the error rather then modifying the package files :

class OrderWizardController extends Controller
{
    use Wizardable, ActionableWizardable {
        ActionableWizardable::getActionMethod insteadof Wizardable;
}

and the trait itself:

trait ActionableWizardable {

    public function getActionMethod(string $method)
    {
        $className = static::class;
        $stepNamespace = config('wizard.namespace.controllers');
        $rootNamespace = trim(str_replace('/', '\\', $stepNamespace), '\\');

        if (Str::startsWith($className, $rootNamespace)) {
            $className = trim($className, '\\');
        } else {
            $className = '\\' . trim($className, '\\');
        }

        return "$className@$method";
    }
}

However would like to dig more to get more understanding on the issue. Hope this will help someone

ycs77 commented

Fixed this bug in v2.3.1, update package and try again.

Update the route file in Laravel 8.x:

no edit will work, but need to uncomment the RouteServiceProvider.php#L29

routes/web.php

use App\Http\Controllers\UserWizardController;
use Illuminate\Support\Facades\Route;
use Ycs77\LaravelWizard\Facades\Wizard;

...

Wizard::routes('wizard/user', UserWizardController::class, 'wizard.user');

Yep, seems it works as expected, thanks @ycs77!