All individual subscriptions are 50% off this week only!

3 months ago

Eloquent Relationship issue

Posted 3 months ago by BenBermingham

I am having issues with a eloquent relationship I am trying to get working on my site and am wondering if anybody knows where I have gone wrong. User.php

public function TrainingProgram() {
    return $this->belongsTo(TrainingProgram::class);


protected $table = 'training_programs';
public function User()
    return $this->hasOne(User::class,'training_program');

Blade file

{{ $avail->user->training_program->name }}

In my training_programs table I have two columns: name and ID, and I can get

{{ $avail->user->training_program}}

to work but not with '->name' attached onto it

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