Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean? With with() is for eager loading . That basically means, along the main model, Laravel will preload the relationship(s) you specify. With đi kèm với khái niệm eager loading, tức là đi kèm với main model, Laravel sẽ load thêm dữ liệu của model có quan hệ với model chính. Ví dụ User > hasMany > Post $users = User :: with ( 'posts' )-> get (); foreach ( $users as $user ){ $users ->post; // posts is already loaded and no additional DB query is run } Has If you just use has('relation') that means you only want to get the models that have at least one related model in this relation. --> là 1 dạng filter (sử dụng where), khi muốn lấy các model chính có ít nhất 1 model con User > hasMany > Post $users = User :: has ( 'posts' )-> get (); // only users that have at least one post are contained in the collection WhereHas whereHas() wor...