spatie/laravel-personal-data-export

Invokable controller not working as intended.

ash123456789 opened this issue · 13 comments

After defining the required route macro, you get the following error.

Invalid route action: [App\Http\Controllers\Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController].

I'm not sure if I'm missing anything, but it seems like invokable controllers just do not work.

If I modify the macro directly to use a defined method, everything works as intended and I no longer get the error.

        Route::macro('personalDataExports', function (string $url) {
            Route::get("$url/{zipFilename}", 'Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController@download')
                ->name('personal-data-exports');
        });

The tests seems to indicate that this is working as intended. Did you already try clearing your route and config cache?

Cleared both route cache and config cache. I also created an invokable controller outside of the package to check if they were working as intended, that didn't seem to work either.

Possible Laravel bug?

Closing this because your error probably isn't caused by our package.

I have the same issue with Laravel 5.8.4. It's coming up with the wrong path for the controller, which is causing the error.

Changing:
PersonalDataExportController::class
to:
'\Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController'
fixes it.

As a work around I put this at the top of my routes (web.php) to avoid changing the package itself:

Route::macro('personalDataExports', function (string $url) {
    Route::get("$url/{zipFilename}", '\Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController')
        ->name('personal-data-exports');
});

same.
I am getting following error
Attribute [PersonalDataExports] does not exist.

I'm not seeing this error. Feel free to submit a PR if a change in our code would resolve this problem for you.

same.
I am getting following error
Attribute [PersonalDataExports] does not exist.

You have to use a lowercase p otherwise you get that error:
Route::personalDataExports('personal-data-exports');

This is based on the fact that Laravel's RouteServiceProvider is applying the App\Http\Controllers namespace by default, then prefixing the \Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController with that namespace.

The override with the full path is a working solution but there might be another one - I'll look into it in a free minute as I must admit it spiked my interest and I don't have an answer this minute.

I'm getting the same error.
Changing the route macro to
Route::get("personal-data-exports/{zipFilename}", '\Spatie\PersonalDataExport\Http\Controllers\PersonalDataExportController@__invoke')->name('personal-data-exports'); fixed the issue.

Freek, your test may turn green but there is definitely a glitch here.

@freekmurze I explained the reason this isn't working above, but couldn't make time to research and issue the pull request
@AlexisSerneels thanks for taking the time !

@satyago You're welcome. Pull request is complete now and totally green.

Merged.

Just had this same error in an internal project and found that it can also be fixed by registering the route with the brackets like this:

Route::get("$url/{zipFilename}", [PersonalDataExportController::class])

@freekmurze would you be interested in a tiny PR that does this?
That does not work.