Passing 2 Parameters to Laravel Routes - Resources

后端 未结 2 1659
广开言路
广开言路 2021-02-09 07:14

I\'m trying to build my routes using resources so that I can pass two parameters into my resources.

I\'ll give you a few examples of how the URLS would look:

         


        
2条回答
  •  萌比男神i
    2021-02-09 08:17

    For the request like '/project/100/file/56968', you must specify your route like this:

    Route::resource('project.file', 'FileController');
    

    And then you can get parameters at the show method of the controller:

    public function show($project, $file) {
        dd([
            '$project' => $project,
            '$file' => $file
        ]);
    }
    

    The result of this example will be:

    array:2 [▼
      "$project" => "100"
      "$file" => "56968"
    ]
    

提交回复
热议问题