Best code snippets, tutorials and more

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

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 […]

Higher order messages in Laravel

Hello friends! In Laravel, you can utilize the shortcut for “higher order messages” that come with collections. This is extremely useful for performing common actions. See the code below:

How to remove a package in Laravel

The best and clean way is to run the terminal command that composer documentation tells: You can also remove multiple packages in a row: Also, don’ forget to remove code that utilizes the package.