Best code snippets, tutorials and more

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

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.

How to retrieve rows by order with raw query in Laravel

There is an orderByRaw method in Laravel that lets you write your custom raw query to retrieve records by order. See the following code example with the task “Get the nearest office for given latitude and longitude”. App\Models\Office.php: To get the nearest office for a given latitude and longitude (columns lat and lng):

How to filter Model records with created_date in Laravel

Often times you need to filter your Model records based on the created_date field. With Laravel, you can make scope Methods after() and before() and use them like below. In case multiple of your Models needs these methods, you can move them to Trait.

Best three ways to lower server requests with Laravel Livewire

One of the first questions they have for people who get started with Livewire is why there are so many separate requests to the server. As you may know, with a change on the Livewire model field, there’s an ajax request or API request. And there are just too many requests to load on the […]

Quick tip on using named routes in Laravel

If you like to use route names in your Laravel projects, this tip might be helpful to you. You can assign the named method on a route instance to find if the current request was directed to a given named route.