laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

Add cast to Model class[Feature Request]

Open mhbesharatnia opened this issue 4 years ago • 2 comments

Hello! I hope to be fine! As I understand, there is not casting support in the models (according to some Issue like this https://github.com/jenssegers/laravel-mongodb/issues/1580 ) I present to add this function to the model:

public function setAttribute($key, $value)
{
    if ($this->hasCast($key)) {
        $value = $this->castAttribute($key, $value);
    }
    return parent::setAttribute($key, $value);
}

mhbesharatnia avatar Feb 11 '21 08:02 mhbesharatnia

Hello,

As I understand, there is not casting support in the models (according to some Issue like this #1580 )

This is an old issue tagged as fixed. How you check it yourself?

Thanks!

divine avatar Feb 11 '21 09:02 divine

Hello,

As I understand, there is not casting support in the models (according to some Issue like this #1580 )

This is an old issue tagged as fixed. How you check it yourself?

Thanks!

It is not fixed for everyone I suggest to add this to fix it in Model layer I used v3.8.2 in this version also if you wand cast property in class that extended from this library Model you should add setAttribute function to class for casting. If this function added to Model every one can use cast without writing more codes.

mhbesharatnia avatar Feb 11 '21 09:02 mhbesharatnia