ycs77 / laravel-wizard

A web Setup Wizard for Laravel application.
MIT License
122 stars 18 forks source link

Package does not play well with Laravel 8 #29

Closed rabol closed 3 years ago

rabol commented 3 years ago

Use Version: Use version when bugs appear.

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 3 years ago

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

vkosachev commented 3 years ago

@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 3 years ago

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');
vkosachev commented 3 years ago

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