Improving my knowledge and skillset is something that I love to do and I felt that learning learning Laravel for PHP was something that I needed to learn.
But what is Laravel? And should you start learning Laravel for PHP?
If you are someone like myself that has come from an ASP.Net(dot net) background then using an MVC (model view controller) coding pattern is something that you will most likely have been using…Laravel is essentially the same. It uses an MVC style coding pattern that ensures cleaner written coding.
How the MVC architectural pattern works is by having a model layer; which is essentially where classes and properties are held, the view layer; this is essentially the front-end view, and is where the data from the model and controller is displayed, and the controller view; this is essentially the middle layer and it contains the coding logic which uses the model layer to populate the data and to also get and return data to the view layer. If you were to write a method or function, it would be in the controller layer.
Thanks to Udemy I was able to get to grips with Laravel by creating a simple CRUD (create, read, upload, delete) application. The purpose was so a user could add a new user with credentials such as name, email address and phone number, save it to a database table, and then have the ability to edit and delete users.
Let’s see what I did.
This is the menu. As you can see it is a simple user menu with an edit and delete link
The Edit user menu – looks the same as the Add User screen except wording.
The process: create a form that submits values from the input fields to the method named ‘update’ in the user controller. Within the method, it uses the model named UdemyUser to find the user using the user id value. Once it has found the id, it will then update that user using the model and the values requested from the view. The edit method above the update method requires just the one parameter – the id, wheres updated also requires the request details. In this method, it requires the id value to populate the form with the user credentials that are called using the model and the database select statement.
Things to improve
I did not use a try/catch statements within my code, and thus any errors that would be found not be handled correctly.
I did not use an alert box when deleting a user. Ideally you should include a dialog message to alert a user if they are going to do something that could have detrimental impact on a system.
For more guides, check-out my blog.