What is a View Composer in Laravel?

What is a View Composer in Laravel

View Composers provide a very elegant solution to a very specific problem. If you have spent some time building in Laravel, you likely have at some point come across the Undefined variable error exception getting thrown from a view file. So you inspect your methods in your controllers, figure out where you forgot to fetch some specific information, then make the fix, and your error goes away.…

How To Select Raw SQL Using Eloquent

How To Select Raw SQL Using Eloquent

In this installment of our games app, we are going to add a sidebar for the main games and reviews views. In other words, when the site user is listing all games to view or all reviews to see, there will be a sidebar displayed. This sidebar will hold information about the games and reviews that have been submitted by users of the site. Specifically, we would like to show the user who has submitted the most games first, the user who has submitted the second most games second, and so on.…

How To Protect Specific Routes With Middleware

How To Protect Specific Routes With Middleware

We have completed setting up a user registration system which allows new users to register and log in, as well as for existing users to log in and log out. This means we have two types of users now of our site. A user is either a guest, or is a registered user. It makes sense then that guest users should have access to certain areas of the site, and be limited to other sections of the site.…

Applying RESTful Methods to the Reviews Resource

Applying RESTful Methods to the Reviews Resource

When we talk about a resource with regard to the RESTful approach to development, we are making use of generic overviews of how to manage a collection of similar items. So far we have really focused on Games as our main resource in our little application. If we want to show all games, we use the index() method. If we want to display a form to insert a new game into the system, we use the create() method.…

A User hasMany Games and also hasMany Reviews

Users Can Add Games and Reviews

When we first started out creating our little games app, we set up a form to add games to the system. We also set up a form to add reviews for games in the system. We were able to establish the relationships between games and reviews. This was all done as a strictly guest based system as we had no user authentication system until just recently.…