in Laravel

Laravel Resource Test Template

If you've used Laravel for some time you'll understand the use of the Controller Resource. It's a quick way of defining the functionality of a controller done to the core 7 functions.

  • Index
  • Create
  • Store
  • Show
  • Edit
  • Update
  • Delete

    I'm a big fan of defining your controllers in this matter as it keeps your controllers simple and defined. Therefore this is a template I try to keep to when creating new controllers, which means the controller will look something like this.

As you can see from the above template it shows a very basic example of how you can create a simple controller with the 7 resources methods to perform specific crud operations on the Post model. The index method is used to display all the posts. Create method will display the form to create a new post. Store is used to save the create form data in the database. Show will display a single post. Edit will display the edit form for the post. Update will change the existing data in the database from the form request. Delete will remove the post from the database and redirect back to the index method. Along with the standard resource methods we also need to cater for the tests of this controller. Below is a good example you can use to construct your controller resource tests. it will go through each of the methods and make sure this working correctly.

Login to access all content on Paulund

Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email