Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

http://laravel.com/docs/4.2/eloquent#has-many-through i think this is what you are looking for.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

What's the relation type between IMPORT and DOCUMENT exactly?

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

endder endder Joined 19 May 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.