Search code examples
laravelmodel

Get record real value after overriding it


I've overridden a a record value like the following :

public function getWeightAttribute($weight)
 {
        if($weight)
        {
          return $weight;
        }

        return 70;
}

Now I have a collection of that model and I want to know if the original value was null or not. I want to do it without connecting to DB again, Actually I want to make sure the user has filled the weight and some other fields while registering. Some sections are working based on the above override and I don't want to mess them up neither use extra connections to db. Thanks In Advance,


Solution

  • In order to get the original value, you can use:-

    $fetchData->getAttributes()['weight'];