on
Italy
- Get link
- X
- Other Apps
// get the cuteness level of a puppy
Route::get('puppies/{cutelevel}', function($cutelevel)
{
return 'This puppy is an absolute ' . $cutelevel . ' out of ' . $cutelevel;
});
// OR
// get the parameter of name
Route::get('users/{name}', function($name)
{
return 'User Name is ' . $name;
});
Testing Cuteness Level: Now in our browser, if we access http://example.com/puppies/5, our browser would show This puppy is an absolute 5 out of 5.http://example.com/users/chris, our browser would show User Name is Chris.
// optional category
Route::get('gallery/{category?}', function($category)
{
// if category is set, show the category
// if not, then show all
if ($category)
return 'This is the ' . $category . ' section.';
else
return 'These are all the photos.';
});
Testing Optional Category: If we visit http://example.com/gallery/puppies, our browser would return This is the puppies section.http://example.com/gallery, our browser will return These are all the photos.
// optional category with a default
Route::get('gallery/{category?}', function($category = 'sunsets')
{
return 'This is the ' . $category . ' category.';
});
Testing No Category: If we visit http://example.com/gallery, then our browser will return This is the sunsets category.http://example.com/gallery/puppies, then our browser will return This is the puppies category.
// get the category of gallery for viewing
Route::get('gallery/{category?}', function($category) {
// get the gallery stuff for the category
$gallery = Gallery::where('category', '=', $category);
// return a view and send the gallery data to the view
return View::make('gallery')
->with('gallery', $gallery);
});
Comments
Post a Comment