Passing Multiple Parameters In Route to Controller in Laravel

We can pass multiple parameter Today in this tutorial, we will learn how to pass multiple parameters through named route to controller method. Passing Multiple Parameters In Route to Controller in Laravel.

Learn about laravel from here Laravel 8 . You can also lean our articles on React js such as OTP Timer in reactjs and Theme color change in ReactJs

In this example, will first define a route with multiple parameters and then we will add a controller method accepting multiple parameters. Then we will setup a link with named route having multiple parameters.

Pass Multiple Parameters Using Route to Controller in Laravel

Laravel helps us to pass multiple route . Now We will see how to define route with parameter

Syntax :

Route::get('test/{paramter1}/{paramter2}', 'PlayGame@method_one');

Example :

Route::get('/posts/view-post/{id}/{name}','PostController@view_post')->name('view.post');

Now define a controller method accepting multiple parameters as below:

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class PostController extends Controller
{

public function show_post($id,$name){
echo $id.' - '.$name;
}

}

Now I will the controlling using an anchor tag button in view folder

 <a class="btn btn-success" href="{{route('view.post',['id'=>$post->id,'name'=>$post->title])}}">Show</a>

This way we can pass Multiple parameter in route .

See our more tutorials on Laravel and ReactJs

Leave a Reply

Your email address will not be published. Required fields are marked *