Controllers are the bosses in the MVC paradigm context. In the Laravel implementation, they get input data, decide what to do with it, and finally show a view that will be rendered in the browser. The controller may also redirect or force actions on the browser with headers. Learn how to generate your controllers with Artisan.
- [Instructor] As most PHP Frameworks Laravel has its own implementation of controllers. As we've already seen Artisan comes with a mechanism to generate controllers from scratch. So taking a look into our CRC cards we see that they're aren't that many controllers that we need for our Landon Hotel App. We just need ClientController, ContentsController, ReservationsController, RoomsContoller and LoginController. So let's generate all of our controllers.
Go to our command line and so let's type PHP Artisan make controller ClientController. Since we already created our ClientController we get this message. The ClientController will hold all the actions that affect the clients. Let's create the next controller with PHP Artisan make controller ContentsController.
This controller will serve for static HTML purposes. Now let's type PHP Artisan make controller ReservationsController. The ReservationsController will show the available rooms in a given timeframe and allow us to book a room. Let's create the next one with PHP Artisan make controller RoomsController.
The RoomsController will allow us to make CRUD a on rooms but that's only if we ever need an interface to modify the rooms. Now let's got to Visual Studio Code. And let's open app, Http, Controllers. Let's refresh and as we see we have our newly created controllers. We will also be using the LoginController. However this already comes with Laravel as a login mechanism ready to be used.
- Laravel file and folder structure
- Dependency injection
- Routing requests to controllers
- Loading a view
- Creating a basic Blade template
- Sending data to a view
- Creating and validating forms
- Integrating a database
- Modifying data with Eloquent
- Returning data to a Laravel view
- Adding relational data and concurrent connections