braed
11 months ago

Undefined Offset exception when accessing a model's attribute

Posted 11 months ago by braed

I have the following example code:

$exhibitor = Exhibitor::first();
$option = $exhibitor->options()->first();

$option has a price attribute of data type decimal that is not mutated. Accessing it gives a Undefined offset: 1 exception:

$option->price; // throws

Why?

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