Page 1 of 1

Laravel custom routes

Posted: 15 Sep 2017, 12:34
by MirkoPinna
I am trying to add a custom middleware in the /checkout route but seems like it doesn't want to work.
I followed the steps at https://aimeos.org/docs/Laravel/Custom_routes
So i added this piece of code to /app/Http/routes.php :

Code: Select all

Route::match( array( 'GET', 'POST' ), 'checkout', array(
		'as' => 'aimeos_shop_checkout',
		'uses' => 'Aimeos\Shop\Controller\CheckoutController@indexAction',
    'middleware' => 'hasPaymentSet',
	));
but nothing happens, i also put this line of code in /config/shop.php :

Code: Select all

'checkout' => ['middleware' => ['auth', 'hasMangopay']],


I run

Code: Select all

php artisan aimeos:cache

and

Code: Select all

php artisan cache:clear
every time but nothing changes.

if i do

Code: Select all

php artisan route:list

i don't see the "checkout" URI listed.

Re: Laravel custom routes

Posted: 15 Sep 2017, 17:02
by aimeos
Can you try to put your route into "./routes/web.php"?
The location of the file changed between Laravel 5.2 and 5.3

Re: Laravel custom routes

Posted: 18 Sep 2017, 07:05
by MirkoPinna
Gives me an error:

Code: Select all

[ReflectionException]                                                                
  Class App\Http\Controllers\Aimeos\Shop\Controller\CheckoutController does not exist 
and if i try to remove this part:

Code: Select all

'uses' => 'Aimeos\Shop\Controller\CheckoutController@indexAction',
it shows in the routes list as follow:

Code: Select all

|        | GET|POST|HEAD | checkout                                                                  | aimeos_shop_checkout         | Closure                                                                | web,hasPaymentSet |
but i go to mywebsite/checkout nothing happens.
I think none of my routes in routes.php is working.

Re: Laravel custom routes

Posted: 18 Sep 2017, 08:02
by aimeos
Seem that Laravel uses a namespace relative to "App\Http\Controllers". Can you add a backslash in front of your controller@action: "\Aimeos\Shop\Controller\CheckoutController@indexAction"?

Re: Laravel custom routes

Posted: 18 Sep 2017, 08:09
by MirkoPinna
Now it finds the controller but nothing happens if i go to mywebsite/checkout, this is the routes list:

Code: Select all

|        | GET|POST|HEAD | checkout                                                                  | aimeos_shop_checkout         | \Aimeos\Shop\Controller\CheckoutController@indexAction                 | web,hasPaymentSet |

Re: Laravel custom routes

Posted: 18 Sep 2017, 09:13
by aimeos
Might be a problem of your "hasPaymentSet" middleware