1. Go to this page and download the library: Download dev1191/laravel-bs-eloquent library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Database\Eloquent\Model;
use Dev1191\BikramSambat\Casts\AsBikramSambat;
use Dev1191\BikramSambat\Concerns\HasBikramSambatScopes;
class Post extends Model
{
use HasBikramSambatScopes;
protected $casts = [
'published_at' => AsBikramSambat::class,
];
}
// You can assign a BS string, DateTime, Carbon, or BsDate instance:
$post = Post::create([
'title' => 'Sample Post',
'published_at' => '2081-01-01',
]);
// In the database table, it's stored as Gregorian '2024-04-14' (preserves indexes!)
// Exact date match
Post::whereBs('published_at', '2081-01-01')->get();
// All posts in Baisakh 2081
Post::whereBsMonth('published_at', 2081, 1)->get();
// All posts in year 2081 BS
Post::whereBsYear('published_at', 2081)->get();
// Date range
Post::whereBsBetween('published_at', '2081-01-01', '2081-01-15')->get();
// Fiscal Year (Aarthik Barsha)
Post::whereBsFiscalYear('published_at', '2081/82')->get();
// Fiscal Quarter (Q1: Shrawan-Ashwin, Q2: Kartik-Poush, Q3: Magh-Chaitra, Q4: Baisakh-Ashadh)
Post::whereBsQuarter('published_at', 2081, 1)->get();
use Illuminate\Foundation\Http\FormRequest;
use Dev1191\BikramSambat\Rules\BsDate;
use Dev1191\BikramSambat\Rules\BsAfter;
use Dev1191\BikramSambat\Rules\BsBefore;
use Dev1191\BikramSambat\Rules\BsFiscalYear;
class StoreInvoiceRequest extends FormRequest
{
public function rules(): array
{
return [
// Using string rules:
'invoice_date' => ['
use Dev1191\BikramSambat\Support\BsDate;
$date = BsDate::parse('2081-01-15');
// Days
$date->addBsDays(5); // 2081-01-20
$date->subBsDays(2); // 2081-01-13
// Months (with automatic month-length day clamping)
$date->addBsMonths(2); // 2081-03-15
$date->subBsMonths(1); // 2080-12-15
// Years
$date->addBsYears(1); // 2082-01-15
$date->subBsYears(2); // 2079-01-15
$date = BsDate::today()->subDays(3);
// In Nepali (natural language with Devanagari digits)
$date->diffForHumans(locale: 'np'); // "३ दिन अगाडि"
// In English
$date->diffForHumans(locale: 'en'); // "3 days ago"
$future = BsDate::today()->addBsMonths(2);
$future->diffForHumans(locale: 'np'); // "२ महिना पछि"
$future->diffForHumans(locale: 'en'); // "in 2 months"
// Just now
BsDate::now()->diffForHumans(locale: 'np'); // "भर्खरै"
BsDate::now()->diffForHumans(locale: 'en'); // "just now"