Best code snippets, tutorials and more

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

How to validate incoming requests in Laravel

Did you know that there are 4 ways to make validation in Laravel for incoming requests? Here they are: 1. Using Request Facades 2. Using Request helper 3. Using Validator Facade 4. Using Form Request

How to use temporary download URLs in Laravel

If you want to prevent unnecessary access to your cloud-based files, you can try temporary download URLs in Laravel. As an example, you can give your user the redirect URL to Amazon S3 storage, and that ULR expires in 5 seconds (it’s more than enough time, but you can play around with this value).

Laravel eager load cheat sheet

What is eager loading? This is an excellent concept for eloquent model in Laravel, when you retrieve the items, you are provided with all the related items at the same query. This eliminates the famous N+1 query problem.

How to test with specific time in Laravel

Hello friends. Sometimes you need to run tests that rely on specific time in the past or in the future. There is a useful trick to fake time for that purpose. Just set fake timestamps using now() helper or Carbon class. Here is the example:

How to not to mess up with Git “master” branch

You always learn something new with Git. For example, you have made many changes to the codebase and suddenly realize that you’re working on a master branch. That seems odd. So, the decision is just as simple as this: This command creates a new branch and brings all of your local changes over.

How to create indexes in the right way

The science of creating database indexes is learned from experience and the right people, not to mention much more complicated multiple-column indexes. But it wasn’t supposed to be complex! Here are three simple pieces of advice for the column ordering of multiple column indexes, solving 90% of the performance issues. Three rules for Multiple-Column Indexes […]