search

Home  >  Q&A  >  body text

laravel ORM problem

1. Use Laravel ORM's associated model. For example, the student table has university_id, University::find(1)->hasManyStudent. In this case, * is obtained instead of the school's data. I want to obtain all of these two models. Data is like MYSQL's innerjoin

为情所困为情所困2757 days ago797

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 16:52:04

    class University
    {
        ...
        public function students()
        {
            return $this->hasMany(Student::class);
        }
        ...
    }
    
    $university = University::with('students')->find(1);
    
    dd($university);
    

    You can see that both types of data are available, students是放在universityin the relationships

    reply
    0
  • Cancelreply