5 months ago

Eloquent relationship collection with name 'links' returning null

Posted 5 months ago by raviteja155

I am running the following query

$course = Course::with(['batches', 'tags', 'links'])->where('slug', $slug)->first();

// when I dump it, I see

#relations: array:3 [▼
    "batches" => Collection {#377 ▶}
    "tags" => Collection {#369 ▶}
    "links" => Collection {#382 ▼
      #items: array:1 [▶]

When I do $course->links it returns null

$course->batches and $course->tags are working fine.

If I change the relationship name links to something else, like courseLinks, I don't have any problem accessing with $course->courseLinks

Why cannot I use links?

Please sign in or create an account to participate in this conversation.