Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
hasMany('ClassName', 'ForeignKey', 'LocalKey');

That's pretty much everything you need.

Mind that ClassName must include namespace if that's the case.

Last updated 2 years ago.
0

Your models look fine.

How about trying this in your view:

@foreach($leads as $lead)
    @foreach($lead->notes as $note) ...
Last updated 2 years ago.
0

Hi luciendub,

Do you have both models defined? Could you please put here your models definition?

Last updated 2 years ago.
0

I found the problem after a good night sleep! I had mispelled Note (Notes) in my Note.php model file. So I removed the "s" and used

@foreach($leads as $lead)
    @foreach($lead->notes as $note)
    {{$note->contenudelanote}}
    @endforeach
@endforeach

as proposed.

Thank you

and here is my Note.php model

<?php
use Illuminate\Database\Eloquent\Collection;
class Note extends \Eloquent {
    protected $table = 'notes';
    protected $fillable = [];
    public function leads()
    {
        return $this->belongsTo('Lead');
    }
}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

luciendub luciendub Joined 29 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.