PHPackages                             bigsinoos/j-eloquent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bigsinoos/j-eloquent

ActiveLibrary[Database &amp; ORM](/categories/database)

bigsinoos/j-eloquent
====================

Convert eloquent date attributes to jalali (Persian) dates on the fly. (supports model propery access, toJson, toString and toArray).

2.2.5(9y ago)214.7k4[1 PRs](https://github.com/reshadman/j-eloquent/pulls)GPLPHP

Since Nov 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/reshadman/j-eloquent)[ Packagist](https://packagist.org/packages/bigsinoos/j-eloquent)[ RSS](/packages/bigsinoos-j-eloquent/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (12)Used By (0)

### Deprecation Notice

[](#deprecation-notice)

For newer versions of Laravel just use the simple attribute casting functionality which is a really nicer approach.

### What is j-Eloquent?

[](#what-is-j-eloquent)

Thanks to Laravel, Django and Rails we all know that convention over configuration (CoC) makes the development more funny. So suppose that you want to convert the Gregorian date attributes of your `Eloquent` models to Jalali (persian) dates, in this case `j-Eloquent` helps you to convert them conventionally, for example when you access a property named `$model->jalali_created_at` on your model, the `PersianDateTrait` detects the convention automatically and tries to convert `created_at` property of your model if it is a date attribute. This is also true for `$model->toJson();` and `$model->toArray();` fields.

#### Installation

[](#installation)

require following line in your composer `require` secion :

```
	"require" : {
			// Other dependecies ,
			"bigsinoos/j-eloquent" : "dev-master" // Laravel 5 , "1.0" for Laravel 4
	}
```

#### Requirement

[](#requirement)

this package requires : [miladr/jalali](https://github.com/miladr/jalali)

#### Features

[](#features)

- Coneventionally converts Eloquent model date attributes to Jalali date when the original date attribute is accessed prefixed by a string like `jalali_`.
- Automatically converts date attributes to Jalali dates when model's `toArrayl`, `__toString();` and `toJson` are called.
- Custom date formats can be set for dates.

#### Documentation

[](#documentation)

##### The `PersianDateTrait` :

[](#the-persiandatetrait-)

By using `\Bigsinoos\JEloquent\PersianDateTrait` trait in your models you can enable the plugin :

```
