Pull multiple rows of a table in laravel 4

I have a table containing

id name 

and a language table containing

 id subject_id 

and partition table

 id name 

final table of subject sections (summary table)

 id subject_id division_id 

now there is a one-to-one relationship between the table of the table of objects and languages ​​and the many-to-many relationship between the table of objects and the division table, I need to pluck only the topics of the subject table without languages, using the relationship function

now I can only get the languages ​​of the object object table of the relationship function in the section model as shown below

  public function langSubject () { return $this->belongsToMany('Subject' , 'subject_division','division_id','subject_id') ->join('lang_subject', 'lang_subject.subject_id' ,'=', 'subject.id')->get(); } 

But so far I can’t get items only without languages

Any suggestions?

+6
source share
2 answers

You need to add the sentence -> select ('tableName1.fieldName1', 'tableName2.fieldName2', 'tableName3.fieldName3') in your statement after the join statement in order to get table_name_name.name, and you may need to use leftJoin instead of a join to get results if there is a match or not.

0
source

Refuse Housing Relationships Documentation → heading under the heading “Request for Relationship”. There he mentions :: has a method that you could use in mod

Division::has('subject.lang', '<', 1)->get()

Or at least that theory. I did not need it yet :-)

It must also be supported by Laravel 4.

0
source

Source: https://habr.com/ru/post/986097/


All Articles