Eloquent doesn’t get the "belongsTo" item

I have the Project model and the Contract model. When i execute Project:all() it gets me only the projects without the contract, same for contract. I tried to dd() inside contract and doesn’t do anything, like is never executed. I also tried with App prefix and without.

use IlluminateDatabaseEloquentModel;
class Project extends Model
{
    protected $table = 'project';

    public function contract() {
        return $this->belongsTo('Contract');
    }
}

namespace App;
use IlluminateDatabaseEloquentModel;

class Contract extends Model
{
    protected $table = 'contract';

    public function project() {
         return $this->hasMany('Project', 'ContractID', 'ContractID');
    }
}


Source: php

Leave a Reply