Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom cast class for laravel >= 7.x #7

Open
ahmed-aliraqi opened this issue Dec 24, 2020 · 1 comment
Open

Add custom cast class for laravel >= 7.x #7

ahmed-aliraqi opened this issue Dec 24, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@ahmed-aliraqi
Copy link

سلام عليكم ورحمة الله وبركاته

Thanks for this amazing package.
I suggest to add custom Casting to convert the dates in get or set automaticlly. as you know the dates should be stored as gregorian in storage but displayed as hijri.

for example in your model add the HijriDate cast:

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'created_at' => HijriDate::class,
    ];
  • HijriDate:
class HijriDate implements CastsAttributes
{
   /**
    * Cast the given value.
    *
    * @param  \Illuminate\Database\Eloquent\Model  $model
    * @param  string  $key
    * @param  mixed  $value
    * @param  array  $attributes
    * @return mixed
    */
   public function get($model, $key, $value, $attributes)
   {
       // Here convert gregorian to hijri;
       return $value;
   }

   /**
    * Prepare the given value for storage.
    *
    * @param  \Illuminate\Database\Eloquent\Model  $model
    * @param  string  $key
    * @param  array  $value
    * @param  array  $attributes
    * @return mixed
    */
   public function set($model, $key, $value, $attributes)
   {
       // Here convert hijri to gregorian;
       return $value;
   }
}

and if you add some tests it will be great 👍

@alkoumi
Copy link
Owner

alkoumi commented Dec 24, 2020

عليكم السلام ورحمة الله وبركاته

الله يبارك فيك أخي أحمد

أفكار جميلة الله يحفظك ، عندي مشاريع في العمل بسلمها وأتفرغ لها بإذن الله تعالى

أسعدني مرورك جدًا

@alkoumi alkoumi self-assigned this Feb 25, 2023
@alkoumi alkoumi added the enhancement New feature or request label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants