Best code snippets, tutorials and more

Coursecomp is your starting point for developing and maintaining your web application.

How to check if a collection is not empty in Laravel

You may ask, why the expression !empty($collection) fails to work (could be a controller or a blade view). The answer is that you have to check the empty state of the collection a bit differently in Laravel. Here is the code: I would prefer the last method as the most self-explanatory one, and it doesn’t […]

How to set up a many-to-many relationship in Laravel

Many-to-many Eloquent relationships are more advanced types of relationships available in Laravel. For example, one blog post can have several categories, and these categories may also be assigned to other blog posts. In this case, we speak about many-to-many relationships, where the post can have many categories and the category may have many posts. Let’s […]