Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamjhn's avatar

Why the query shows "Property [certificate] does not exist on this collection instance."?

Do you know why this query is not working? To get the certificate content associated with the selected registration type.

            $certificate = RegistrationType::find($sendTo)->certificate;
            dd($certificate);

Certificate model:

class Certificate extends Model
{
    protected $fillable = ['content'];

    public function registration_types(){
        return $this->hasMany('App\RegistrationType', 'certificate_id');
    }
}

RegistrationType model:

 public function certificate(){
        return $this->belongsTo('App\Certificate', 'certificate_id');
    }
0 likes
5 replies
tykus's avatar

Are you sure that is where the error is coming from? This should return only a single instance, and chaining certificate would be valid;

RegistrationType::find($sendTo)

If you were doing something like the following, then you would have a Collection:

RegistrationType::get()

// or

RegistrationType::all()
1 like
adamjhn's avatar

Thanks, with only "$certificate = RegistrationType::find($sendTo);" dont shows error, shows:

Collection {#308 ▼
  #items: array:1 [▼
    0 => RegistrationType {#300 ▼
      #fillable: array:7 [▶]
      #dates: array:2 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:11 [▶]
      #original: array:11 [▶]
      #changes: []
      #casts: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
  ]
}
tykus's avatar

Did you override Model's find method in the RegistrationType model?

1 like
adamjhn's avatar

No, in RegistrationType model I just have this methods:

 public function conference(){
        return $this->belongsTo('App\Conference');
    }

    public function questions(){
        return $this->belongsToMany('App\Question', 'registration_type_questions')->withPivot(['required']);;
    }

    public function participants(){
        return $this->hasMany('App\Participant');
    }

    public function presentPrice(){
        return money_format('%i€', $this->price);
    }

    public function registrations(){
        return $this->belongsToMany('App\Registration', 'registration_registration_types');
    }

    public function certificate(){
        return $this->belongsTo('App\Certificate', 'certificate_id');
    }
tykus's avatar
tykus
Best Answer
Level 104

By default, find() should return a single model instance or null unless $sendTo is an array??

1 like

Please or to participate in this conversation.