Home > Backend Development > PHP Tutorial > Laravel 5 routing passes value to function

Laravel 5 routing passes value to function

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:29
Original
1205 people have browsed it

For example, Controller has a function

<code>public function test($var) {
    //some code...
}</code>
Copy after login
Copy after login

How to call Controller's test('abc') when defining get/abc in routes.php?
There is no need for generic variables such as Route::get(/{var}', function($var)...This is because the value of $var is fixed.

Reply content:

For example, Controller has a function

<code>public function test($var) {
    //some code...
}</code>
Copy after login
Copy after login

How to call Controller's test('abc') when defining get/abc in routes.php?
There is no need for generic variables such as Route::get(/{var}', function($var)...This is because the value of $var is fixed.

<code>Route::get('/{var}',function($var){
    return $var;
})->where('var','a|b|c|d|e|f|g');</code>
Copy after login

Request objects can also be obtained.

<code>// URL: /portal/orders/2
public function _test(Request $request)
{
    // 1: portal
    // 2: orders
    // 3: 2
    return Request::segment(1);
}</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template