Because you have a transaction without a course
<td>{{ $transaction->course->title ?? 'no course!' }}</td>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone, please help me, i got the error Attempt to read property "title" on null. Is anyone know why I got this error?, the following is my code:
Controller
public function customerdetail($id)
{
$customer = Customer::findOrFail($id);
return view('admin.detail-customer',[
'customer' => $customer
]);
}
At Blade
@foreach($customer->transactions as $transaction)
<tr>
<td>{{ $transaction->course->title }}</td>
</tr>
This is my model:
Transaction Model:
public function schedule()
{
return $this->belongsTo(Ul_coursemeta::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function course()
{
return $this->belongsTo(Course::class);
}
Customer model:
public function transactions()
{
return $this->hasMany(Transaction::class);
}
Course model:
public function schedules()
{
return $this->hasMany(Ul_coursemeta::class);
}
Please help me. Thank u so much.
Please or to participate in this conversation.