Full Stack Web Developer (Q1-Q2 2021)
Laravel: Implementing CRUD and Using Blade
I’d like for us to now focus on implementing CRUD functionality into our Laravel project for our specific model (i.e. database table) that you chose from the last lesson. (For reference I’ll include the options again below.)
|Customers||The table should all the customer specific details, such as name and contact details (address, email, phone) and etc.|
|Addresses||This database table should be capable of holding records of all UK postal addresses, therefore you’ll most likely need a column for each line of address as minimum.|
|Stores||As this database relates to a retail commerce system, this table should hold records of each store. Column examples could include the store name, id, region and address.|
|Colleagues||This is similar to the customers’ table however should be specific only to store colleagues. We’ll still need to capture their names, email address and also a colleague id.|
|Cities||This table should hold records on each city or town in the UK, therefore at minimum we should have a ‘name’ column as well as area dialling code.|
From the above, we created migrations, models and seeds to get us started with working with databases in Laravel.
I’d like to advance further on our database tables by implementing CRUD functionality to them, i.e. the ability to Create, Read, Update and Delete records. For example the ability to create, edit and delete ‘city’ records in the ‘cities’ table. We did explore CRUD previously however I’d like for us to achieve this using Laravel this time around, which makes it quite easy for us to implement.
Laravel provides us with controllers with the CRUD methods/functions already in place, as well as the ‘resource’ routing feature. You can read more about it on the Laravel Docs under the “Resource Controllers” section.
When implementing CRUD functionality for your specific table, there should be a front-end (e.g. using Bootstrap and HTML forms) to create, edit and delete new and existing records.
Please follow the “Laravel 8 CRUD Operations with Bootstrap 4 Tutorial with Example: Create, Validate, Store Data in Database” guide on RemoteStack to achieve this, which also explores some of the features of Blade too.
After we’ve implemented CRUD functionality in Laravel with our Model, using the Controller and then returning a View (using Blade), you'll be ready to begin developing some practical web applications as we have covered the core aspects of the Laravel framework.