Writing the first routes

Let's start by writing the first two routes of our application at app/Http/routes.php. This file already contains some comments as well as a couple of sample routes. Remove the existing routes (but leave the opening <?php declaration) before adding the following routes:

Route::get('/', function() {
  return 'All cats';
});

Route::get('cats/{id}', function($id) {
  return sprintf('Cat #%s', $id);
});

The first parameter of the get method is the URI pattern. When a pattern is matched, the closure function in the second parameter is executed with any parameters that were extracted from the pattern. Note that the slash prefix in the pattern is optional; however, you should not have any trailing slashes. You can make sure that your ...

Get Laravel 5 Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.