Download the PHP package dev1191/laravel-bs-eloquent without Composer
On this page you can find all versions of the php package dev1191/laravel-bs-eloquent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dev1191/laravel-bs-eloquent
More information about dev1191/laravel-bs-eloquent
Files in dev1191/laravel-bs-eloquent
Package laravel-bs-eloquent
Short Description First-class Bikram Sambat (Nepali Date) Eloquent casts, scopes, and validation for Laravel 10 - 13
License MIT
Homepage https://github.com/dev1191/laravel-bs-eloquent
Informations about the package laravel-bs-eloquent
First-class Bikram Sambat (Nepali Date) Eloquent Casts, Scopes, and Validation for Laravel 10 - 13
A modern, high-performance Laravel package for Bikram Sambat (BS / Nepali Date). It stores standard Gregorian (AD) dates in your database to preserve SQL index performance, while giving you transparent Eloquent casts, scopes, Nepali fiscal year calculations, and a full suite of FormRequest validation rules.
✨ Key Features
- Automatic Eloquent Date Casting (
AsBikramSambat): Write BS dates directly ($model->published_at = '2081-01-01') and let the cast automatically convert and store them as Gregorian ('2024-04-14'). When retrieved, you get a richBsDateobject. - Configurable API / JSON Serialization: Serialize dates as
dual({"ad": "2024-04-14", "bs": "2081-01-01"}), plainbs("2081-01-01"),ad, or full object details. - Index-Preserving Eloquent Scopes (
HasBikramSambatScopes):whereBs('column', '2081-01-01')whereBsMonth('column', 2081, 1)whereBsYear('column', 2081)whereBsBetween('column', '2081-01-01', '2081-01-31')whereBsFiscalYear('column', '2080/81')whereBsQuarter('column', 2081, 1)
- Built-in Nepal Fiscal Year (Aarthik Barsha): Full support for fiscal years (Shrawan 1 to Ashadh 31/32) and quarterly divisions (Q1-Q4).
- Fluent Date Arithmetic & Period Boundaries: Easily manipulate dates (
addBsDays,subBsMonths,startOfBsFiscalYear,endOfBsMonth). - Carbon Status Checks: Built-in boolean state and comparison methods (
isToday(),isYesterday(),isTomorrow(),isPast(),isFuture(),isCurrentMonth(),isCurrentYear(),isSameMonth(),isSameYear()). - Relative Time Localization (
diffForHumans): Natural Nepali and English relative timestamps (e.g., “३ दिन अगाडि”, “२ महिना पछि”, or “3 days ago”). - Extended Formatting Tokens: Full token mapping mimicking PHP's
date()syntax (e.g.l,D,F,M,t,S,Q,x) with Devanagari numerals. - Validation Rules: Complete suite of Laravel validation rules:
bs_date,bs_after,bs_before,bs_fiscal_year. - Artisan CLI Conversion Tool (
php artisan bs:convert): Instant terminal conversion for any BS or AD date directly from the command line, showing Gregorian equivalent, fiscal year, fiscal quarter, and Devanagari output. - Pure Astronomical Formula Engine: Zero hardcoded calendar arrays or third-party packages. Calculates dates directly from planetary motion, Lahiri Ayanamsa, and solar Sankranti ingress moments.
- Devanagari Numerals & Nepali Month Names: Convert and format seamlessly in Nepali (e.g.
२०८१-०१-०१,बैशाख).
📦 Installation
Install the package via Composer:
Publish the configuration file (optional):
The published config/bikram-sambat.php:
🚀 Usage
1. Eloquent Model Casting
Add the cast to your model:
Writing BS Dates:
Reading BS Dates:
2. Eloquent Query Scopes
All queries automatically convert BS boundaries to Gregorian dates so your SQL index remains fast and untouched:
3. FormRequest Validation Rules
Use custom validation rules or standard string rule aliases:
4. Artisan CLI Conversion
Output:
5. Date Manipulation & Carbon Parity (BsDate)
The BsDate object provides Carbon-like fluent operations designed specifically for Bikram Sambat calendar rules:
Fluent Date Arithmetic:
Period Boundaries:
Relative Time Localization (diffForHumans):
Extended Format Tokens:
$date->format($pattern, inDevanagari: false, locale: null) supports standard PHP date() specifiers adapted to BS:
| Token | Description | Example (BS) |
|---|---|---|
d |
2-digit day of month with leading zeros | 01 to 32 |
j |
Day of month without leading zeros | 1 to 32 |
l |
Full day of the week | Sunday / आइतबार |
D |
3-letter / short day of the week | Sun / आइत |
w |
Numeric day of week (0 for Sunday, 6 for Saturday) | 0 |
N |
ISO-8601 numeric day of week (1 for Monday, 7 for Sunday) | 7 |
S |
English ordinal suffix for the day | st, nd, rd, th |
m |
2-digit month with leading zeros | 01 to 12 |
n |
Month without leading zeros | 1 to 12 |
F |
Full month name | Baisakh / बैशाख |
M |
Short month name | Bai / बै |
t |
Number of days in the given BS month | 31 |
Y |
4-digit BS year | 2081 |
y |
2-digit BS year | 81 |
L |
Whether it is a leap year (366 days) | 1 or 0 |
Q |
Fiscal quarter (1 to 4) | 4 |
x |
Fiscal year string | 2080/81 |
Carbon Status Checks:
5. Artisan CLI Conversion Command
Quickly inspect and convert dates directly from the command line without opening a tinker session:
Sample Output:
🧪 Testing
Run tests with Pest:
🤝 Contributing
Please see CONTRIBUTING.md for detailed guidelines on the Git workflow, branching strategy, testing requirements, and commit conventions.
📄 License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-bs-eloquent with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0 || ^11.0||^12.0||^13.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/validation Version ^10.0 || ^11.0 || ^12.0 || ^13.0
nesbot/carbon Version ^2.62 || ^3.0