Support the ongoing development of Laravel.io →
Requests Input

Hello,

I'm trying to create a list of links, generated as a response to some input. The links need to carry over 2 parameters, so I was thinking of doing that with ?param1=foo,param2=bar. However all methods for creating URLs seem to generate /foo/bar at the end of the URL.

Is that the 'preferred' way of passing info? And if so, what would be standard way for getting this info, Request::segment() ?

Regards, Jan.

Last updated 3 years ago.
0
Solution

Its simple just create route with param in url.

// routes.php
Route::get("/user/{id}", array("uses" => "UserController@show", "as" => "user.show");


// UserController.php
class UserController extends BaseController {

	public function show($id)
	{
		echo "User id: ".$id;
	}

}

// Usage

URL::route("user.show", array(1));  // generate link to web.com/user/1
Last updated 3 years ago.
0

Pretty nice indeed, and it also works well with 2 params (like /user/{firstname}/{lastname})
Now just need to work out how I can make it play with my rest-routing :(

Last updated 3 years ago.
0

Well, turns out to be much more easy than I thought, so my route looks like this:

Route::controller('tool/sitereport', 'SiteReportController');

tool/sitereport/report/param1/param2 would hand over to the getReport function with the two segments as parameters, so

public function getReport($param1, $param2)
{
    return $param1 . ', ' . $param2;
}

just works like a charm!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.