Skip to main content
100%

Accessor can't be accessed through HasMany Relationship

✓ Published0🌍 Public
NNaoray
Last edited Jan 11, 2018
Created on Jan 11, 2018

This example demonstrates a bug in Laravel's Eloquent ORM where accessors defined on a model cannot be accessed through a HasMany or BelongsTo relationship. The code shows a `Project` model with a `getFooAttribute()` accessor and a `User` model with a `getBarAttribute()` accessor. While direct access like `Project::first()->foo` correctly returns 'Bar', accessing the same accessor through a relationship chain like `Project::first()->users->first()->bar` returns `null`. The issue is reproduced using Laravel's Eloquent model relationships and accessor methods.

AI-generated description

Similar vizzes