Trying to get property 'parent' of non-object after i use accessor

Viewed 14

I want to encrypt the value of my parent column in my table after fetching it.

now it returns Trying to get property 'parent' of non-object, how am I able to fix this?

here is my code for fetching the data in my controller

    function getParents($id){
        global $crumbs;
        $parent = Accreditation::where('id', $id)->first(['id', 'title', 'set', 'parent']);
        $par = Crypt::decryptString($parent->parent);
        if($parent != null){
            array_unshift($crumbs, json_decode($parent));
            getParents($par);
        }
    }

    //$id is parameter
    if($id != null || is_numeric($id) == 1){
        getParents($id);
    }

and in my model, I have this

class Accreditation extends Model
{
  use HasFactory;

  public function getIdAttribute($value)
  {
      return Crypt::encrypt($value);
  }

  public function getParentAttribute($value)
  {
      return Crypt::encryptString($value);
  }

  public function getAccredIdAttribute($value)
  {
      return Crypt::encrypt($value);
  }
}

after adding the getParentAttribute() it display

ErrorException Trying to get property 'parent' of non-object

0 Answers
Related