http://laravel.com/docs/4.2/eloquent#has-many-through i think this is what you are looking for.
SerdarSanri said:
http://laravel.com/docs/4.2/eloquent#has-many-through i think this is what you are looking for.
Hay SerdarSanri
I have tried this in the past and couldn't get it to work right, sorry should have mentioned that in my post.
What's the relation type between IMPORT and DOCUMENT exactly?
jarektkaczyk said:
What's the relation type between IMPORT and DOCUMENT exactly?
REF is the link column e.g.
USERS table ID links to IMPORT table USER_ID, IMPORT table REF links to DOCUMENT table REF.
hope this helps
You need three Model classes. Al
class User{
....
public function imports(){
return $this->hasMany("Import");
}
public function documents(){
return $this->hasManyThrough("Import", "Document", "user_id", "ref");// we need to define local and parent keys because in your table you are not using {model}_id naming.
}
....
}
class Import{
.....
public function documents(){
return $this->hasMany("Document" , "ref" , "ref"); // we need to define local and parent keys because in your table you are not using {model}_id naming.
}
.....
}
class Document{
.....
public function users(){
return $this->hasManyThrough("Import", "User" , "ref" , "user_id");
}
public function imports(){
return $this->belongsTo("Import", "ref" , "ref");// we need to define local and parent keys because in your table you are not using {model}_id naming.
}
.....
}
now in your view, you can either get all imports and get documents() from each one or get all documents by
@foreach($user->documents() as $document)
<p>{{$document->content}}</p>
@endforeeach
I haven't tested the code but I think at least it will give you the idea.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community