Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass variable in route name in laravel?

Tags:

php

laravel

I have defined route

Route::get('/edit-industry/{id}', 'Industries@edit')->name('admin.editIndustry'); 

And passing variable by

{{ route('admin.editIndustry', ['id'=>1]) }} 

OR

{{ route('admin.editIndustry', [1]) }} 

This is not working. How to pass variable here?

like image 465
salin kunwar Avatar asked Aug 18 '17 08:08

salin kunwar


People also ask

How can pass query string in URL in Laravel?

You can pass query string to URL in laravel using named route and controller action. You can pass query string as comma separated array to named route and controller action and redirect to URL.


2 Answers

wow, why are wrong answers (or answers for questions which were not asked in this case) upvoted?

EkinOf is correct, you can do

{{ route('admin.editIndustry', 1) }} 

Btw your first one works too and is necessary, if you have more than 1 parameter

{{ route('admin.editIndustry', ['id'=>1]) }} {{ route('admin.editIndustry', ['id'=>1, 'something'=>42]) }} 
like image 192
Inuyaki Avatar answered Oct 13 '22 03:10

Inuyaki


If you have only one parameter you can do that :

{{ route('admin.editIndustry', 1) }} 
like image 33
EkinOf Avatar answered Oct 13 '22 02:10

EkinOf