Skip to content
Advertisement

How do I pass a parameter to a controller action within a Laravel Package?

Within a Laravel package I made, I want to redirect the user to a controller action that requires a parameter (within the same package).

Controller:

JavaScript

The action in the redirect is the same path I use in my routes.php file to direct the user to this controller action

Route:

JavaScript

I’ve tried variations of this path without success, including SpotBuyController@getPart like the documentation suggests (https://laravel.com/docs/5.1/responses#redirects)

Note: I got this to work by naming my route in routes.php and using return redirect()->route('route_name', [$id]);, but I still want to know how to pass a package controller action to the ->action() function.

Advertisement

Answer

It’s trying to access your controller from within the AppHttpControllers namespace. Can see they’ve added it to your controller name in your error:

AppHttpControllersArielSpotBuyHttpControllersAdminSpotBuyController@getP‌​art

You need to escape the Ariel namespace with a at the start:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement