Best code snippets, tutorials and more

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

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.