Laravel Date Scopes - A package to filter eloquent models by common date ranges conveniently

July 31, 2023
Zacharias Creutznacher
Zacharias Creutznacher
Chief Technology Officer (CTO)

Usage

When you filter and query eloquent models by given dates, you may often use similar ranges, especially in statistics or analysis. Here our package Laravel Date Scopes comes in to play. It lets you conveniently filter by date, with common statistical ranges.

You can easily install the package by requiring it via composer:

composer require laracraft-tech/laravel-date-scopes

Let's assume you have an Transaction model class. Now when you give it the DateScopes trait (which comes with the package), you can use the following scopes:

For a full list of available ranges, checkout the documentation here!

Understanding Inclusive/Exclusive

It's important to understand this difference:

In statistics, when asking for "the last 7 days", the current day may or may not be included in the calculation depending on the context and the specific requirements of the analysis.

If you want to include the current day in the calculation, you would generally use an inclusive range, meaning that you would include records created on the current day as well as records created in the previous 6 days.

If you want to exclude the current day in the calculation, you would generally use an exclusive range, meaning that you would include records created in the previous 7 days, but not records created on the current day.

Ultimately, it depends on the context and what you're trying to achieve with your data. It's always a good idea to clarify the requirements and expectations with stakeholders to ensure that you're including or excluding the correct records.

The same concept applies to other time intervals like weeks, months, quarters, and years etc.

The default for this package is exclusive approach, which means when you for instance query for the last 7 days it will not include the current day! You can change the default if you need in the published config file.

code

What’s a Rich Text element?

The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.

Static and dynamic content editing

A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!

How to customize formatting for each rich text

Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.

H4

H5
H6

http://google.de

<code>test123<code>

<span style="color:red;">asdfasdf</span>

composer require spatie/laravel-artisan-dispatchable

Setzen Sie Ihre Ideen um!
Heute ist der Tag, um das Geschäft Ihrer Träume aufzubauen. Teilen Sie Ihre Mission mit der Welt – und begeistern Sie Ihre Kunden.
Jetzt starten