Instead of writing logic in the routes.php, you can separate and organize your application logic into a controller. Controller class is by default located in app/controllers directory, but you can move it to another directory as long as it registered in composer.json

And now we can add route to this controller in app/routes.php

RESTful Controller

SlimStarter allows you to easily define a single route to handle every action in a controller using simple, REST naming conventions using the Route::controller method:

this will map every access to /book to be handled by BookController

Resource Controller

Resource controller make it easier to build RESTful controllers around resources. For example, you may wish to create a controller that manages “books” stored by your application.

this will map several route to BookController as listed below