Laravel How To Pass Multiple Parameters into Route Tutorial

Reading Time: 4 minutes
975 Views

Inside this article we will see the concept i.e Laravel How To Pass Multiple Parameters into Route Tutorial. Article contains the classified information about Defining routes with multiple parameters in laravel.

If you are looking to find a solution for Laravel Passing Multiple Parameters In Route to Controller then you are at the right place to learn and implement. Additionally we will see passing multiple parameters with Model binding concept.

Read More: How To Add Custom Attribute in Laravel Model Tutorial

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Example #1: Pass Multiple Parameters into Route

Suppose, we have a User controller. We will consider these sample data only to learn and understand.

Define Route

Code of web.php,

web.php

Get All Parameters in Controller

Read More: How to Use DB Raw Query in Laravel Explained Tutorial

Code of UserController.php,

UserController.php

How To Create Link To this Route

Code of a blade template file,

<a href="{{ route('users.posts.show', ['user_id' => 1, 'post_id' => 10]) }}">Show</a>

Example #2: Pass Multiple Parameters with Model Binding

Again, we have a User controller. We will consider these sample data only to learn and understand.

Define Route

Code of web.php,

web.php

Get All Parameters in Controller

Read More: Laravel How To Get Min Value of Column Tutorial

Code of UserController.php,

UserController.php

How To Create Link To this Route

Code of a blade template file,

<a href="{{ route('users.posts.show', ['user_id' => 1, 'post_id' => 10]) }}">Show</a>    

We hope this article helped you to learn about Laravel How To Pass Multiple Parameters into Route Tutorial in a very detailed way.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.