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:

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.