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.
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
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 :(
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!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community