Hi, I am working on my first application. I created two database tables: "leads" and "notes. I would like to show the notes for each lead. Actually, I try to figure out how to do this. I tried different things playing with "hasmany" in the "Lead" and "Note" model but it doesn't work. Laravel tells me that it cannot find the "Note" class.
How should I do?
Here is my complete application .zip
hasMany('ClassName', 'ForeignKey', 'LocalKey');
That's pretty much everything you need.
Mind that ClassName
must include namespace if that's the case.
Your models look fine.
How about trying this in your view:
@foreach($leads as $lead)
@foreach($lead->notes as $note) ...
Hi luciendub,
Do you have both models defined? Could you please put here your models definition?
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');
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community