简体   繁体   中英

Laravel route get wrong param value

I have tried to inject local in route and it's working but when working on another route there is a issue appear to me first this is my web.php route contents

Route::group(['prefix' => '{local}' ], function () {

    Route::get('/question/view/{question}/{slug?}', 'QuestionsController@show')->name('question_view');

});

then in inside show function

public function show($question, $slug)
{
    dd($question,$slug);
    //print en, 1
}

this is a url I have called

http://localhost:8000/en/question/view/1/hello

when I'm trying to read the value of question I got the local value en ! where is wrong ?

You have 3 params in route

public function show($prefix, $question, $slug)
{
    dd($prefix, $question,$slug);
    //print en, 1, hello
}

As your route have 3 param local , question and slug , your url will take that 3 param respectively , so try to take 3 param in function as well like

public function show($local, $question, $slug)
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM