{"id":13763018,"url":"https://github.com/reshadman/j-eloquent","last_synced_at":"2026-01-11T02:27:26.487Z","repository":{"id":20995623,"uuid":"24285197","full_name":"reshadman/j-eloquent","owner":"reshadman","description":"Convert eloquent date attributes to Jalali (Persian) dates on the fly, With the help of convention over configuration.","archived":false,"fork":false,"pushed_at":"2021-08-23T20:13:11.000Z","size":16,"stargazers_count":21,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T14:53:26.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reshadman.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-21T07:40:51.000Z","updated_at":"2025-03-25T07:52:47.000Z","dependencies_parsed_at":"2022-07-31T05:18:04.156Z","dependency_job_id":null,"html_url":"https://github.com/reshadman/j-eloquent","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshadman%2Fj-eloquent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshadman%2Fj-eloquent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshadman%2Fj-eloquent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshadman%2Fj-eloquent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reshadman","download_url":"https://codeload.github.com/reshadman/j-eloquent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253445611,"owners_count":21909826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T15:00:27.496Z","updated_at":"2025-05-10T16:32:09.115Z","avatar_url":"https://github.com/reshadman.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Persian Tools"],"readme":"### Deprecation Notice\nFor newer versions of Laravel just use the simple attribute casting functionality which is a really nicer approach.\n\n### What is j-Eloquent?\nThanks 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-\u003ejalali_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-\u003etoJson();``` and ```$model-\u003etoArray();``` fields.\n\n#### Installation\nrequire following line in  your composer ```require``` secion : \n\n\n```javascript\n\n\t\"require\" : {\n\t\t\t// Other dependecies ,\n\t\t\t\"bigsinoos/j-eloquent\" : \"dev-master\" // Laravel 5 , \"1.0\" for Laravel 4\n\t}\n\n```\n\n#### Requirement\n\nthis package requires : [miladr/jalali](https://github.com/miladr/jalali)\n\n\n#### Features\n\n- Coneventionally converts Eloquent model date attributes to Jalali date when the original date attribute is accessed prefixed by a string like ```jalali_```.\n- Automatically converts date attributes to Jalali dates when model's ```toArrayl```, ```__toString();``` and ```toJson``` are called.\n- Custom date formats can be set for dates.\n\n\n#### Documentation\n\n##### The ```PersianDateTrait``` :\nBy using ```\\Bigsinoos\\JEloquent\\PersianDateTrait``` trait in your models you can enable the plugin : \n```php\n\u003c?php\n\nclass Role extends \\Eloquent {\n    use \\Bigsinoos\\JEloquent\\PersianDateTrait;\n    protected $table = 'roles';\n}\n```\n\n#### Usage\nBy default you can access your eloquent date attributes in jalali date by adding a ```jalali_``` substring to the begining of your original attribute like ```jalali_created_at``` :\n\n```php\n    $userPremiumRole = Auth::user()-\u003eroles()-\u003ewhere('type', 'premium');\n    $userPremiumRole-\u003ecreate_at; // 2014/12/30 22:12:34\n    $userPremiumRole-\u003ejalali_created_at; // 93/09/08\n```\n\n##### Changing ```jalali_``` prefix\nYou can change the jalali date convention prefix with overriding ```$model-\u003esetJalaliFormat($format)``` and ```$model-\u003egetJalaliFormat();``` or by overrriding ```$model-\u003ejalaliDateFormat``` property on your model class :\n\n```php\n\nclass Role extends \\Eloquent {\n\n    use \\Bigsinoos\\JEloquent\\PersianDateTrait;\n\n    protected $jalaliDateFormat = 'l j F Y H:i';\n}\n\n# or\n\nclass Role extends \\Eloquent {\n    \n    use \\Bigsinoos\\JEloquent\\PersianDateTrait;\n    \n    public function setJalaliFormat($format){\n        // do custom things here\n        $this-\u003ejalaliDateFormat = $format; return $this;\n    }\n    \n    protected function getJalaliFormat()\n    {\n        // return any format you want\n        return 'l j F Y H:i';\n    }\n\n}\n\n```\n\n##### Custom date attributes : \nYou can tell Eloquent that which one of your fields are date attributes like created_at and updated_at, then Eloquent treats them like ```Carbon``` objects you define multiple date attributes like this :\n\n```php\n\nClass Role extends \\Eloquent {\n    \n    use \\Bigsinoos\\JEloquent\\PersianDateTrait;\n    \n    /**\n    * Add this method to customize your date attributes\n    *\n    * @return array\n    */\n    protected function getDates()\n    {\n        return ['created_at', 'updated_at', 'expired_at'];\n    }\n    \n}\n```\nWhen using the above trait all of the fields that are treated like date objects by Laravel will be available for conventional converting. They will be also added to model's ```toJson()``` , ```toArray();``` and ```__toString();``` methods.\n\n##### Converter helper method\n\nThe ```$model-\u003econvertToPersian($attribute, $format);``` method allowes you to normally convert one of your fields, from Gregorian date to Jalali date :\n\n```php\n\n$user = Auth::user();\n$user-\u003econvertToPersian('created_at', 'y/m/d'); // 93/09/08\n\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshadman%2Fj-eloquent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freshadman%2Fj-eloquent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshadman%2Fj-eloquent/lists"}