lundi 26 avril 2021

Larave BelongsTo relationship returns null

I have two Eloquent models:

1) Project :

class Project extends Model
{
    protected $table = 'projects';
    protected $fillable = ['id', 'user_id', 'account_id'];

    public function user(){
        return $this->belongsTo(User::class);
    }

    public function account()
    {
        return $this->belongsTo(Account::class, "account_id");
    }

2) Account :

class Account extends Model
{
    // ...

    public function projects(){
        return $this->hasMany(Project::class);
    }

The goal is to have returned the account of the project :

Project::with("account")->get()->pluck("account");

Result :

null


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3xsne6H
via IFTTT

Aucun commentaire:

Enregistrer un commentaire