problem with eloquent relationship

Posted 10 months ago by RossUK

Hi, I have two models called CallLog and Job. CallLog belongs to Job.

class CallLog extends Model
     protected $table = 'call_log';

    public function job()
        return $this->belongsTo(Job::class, 'job_id');

Job includes the fields type,status,name

I am strugling to get the job name value

as a test if I run tinker and enter the following

$calllog = App\CallLog::find(5);
$job = $calllog->job;
$status = $job->status;
// I get the value I expect
=> "Completed"

however if I do the same with name eg. I get null

$calllog = App\CallLog::find(5);
$job = $calllog->job;
$name = $job->name;
// I get null
=> "null"

When I find the job I can see the name value set?

>>> $job = $calllog->job;
=> App\Job {#2937
     id: 4,
     created_at: "2018-09-12 21:12:25",
     updated_at: "2018-09-12 21:48:15",
     name: "test9",
     status: "Sent",

Is there a problem using the field name "name"? If i temporarily change the field name to name2 it works fine. Everything else that uses this table field name works fine which is why I am confused. Although this is the first time I have used this field name in a relationship :)

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