Passing route parameters to the route() helper in Laravel 5.4

There are a few different ways to pass these parameters. Let’s imagine a route defined as users/{userId}/comments/{commentId}. If the user ID is 1 and the comment ID is 2, let’s look at a few options we have available to us.

Option 1

route('', [1, 2])

Option 2

route('', ['userId' => 1, 'commentId' => 2])


Option 3

route('', ['commentId' => 2, 'userId' => 1])


Option 4

route('', ['userId' => 1, 'commentId' => 2, 'opt' => 'a'])


Non-keyed array values are assigned in order; keyed array values are matched with the route parameters matching their key and anything left over is added as a query parameter.


Popular posts from this blog

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'

Regular Expression Route Constraints And Route Names in Laravel 5.4