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

Laravel 5 routing passes value to function

WBOY
WBOYOriginal
2016-08-04 09:19:291178browse

For example, Controller has a function

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

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>

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>

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>
Statement:
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