Creating Controllers in Laravel is super simple. In an MVC pattern, controllers play a vital role and defining your all request handling logic as an anonymous function in route file is unthinkable for a big application.
So we always use controllers as a transport medium. The main advantage of a controller is it can group all the request handling into a single class and that class can be stored in the ‘app/HTTP/Controllers’ directory.
There are a few ways to create a controller and we can always add some functionalities into it later to use features such as Middleware.
You can create a basic controller by using this command:
$ php artisan make:controller MyController
However, for a big application such as what we are going to create, it is always wise to create a resourceful controller.
When you issue such command:
$ php artisan make:controller MyController –resource
Laravel creates a controller class that automatically adds typical “CRUD” routes to the controller. This single line of code generates all types of methods that we usually require to create, retrieve, update and delete records. Continue reading