Eloquent relationships
Në shqip: Marrëdhëniet në Eloquent
ShpjegimiSQ
Në Eloquent, lidhjet mes tabelave shkruhen si metoda: hasMany (një kategori ka shumë terma), belongsTo (një term i përket një kategorie), belongsToMany. Me with() i ngarkon bashkë dhe shmang problemin „N+1 query“.
EnglishEN
In Eloquent, links between tables are written as methods: hasMany (a category has many terms), belongsTo (a term belongs to a category), belongsToMany. With with() you load them together and avoid the “N+1 query” problem.
Si ta mendosh
Si pema familjare: prindër, fëmijë, kushërinj — të lidhur me vija.
Lexoje në anglisht
Like a family tree: parents, children, cousins — joined by lines.
Shembull kodiphp
<?php
class Kategoria extends Model {
public function termat() { return $this->hasMany(Termi::class); }
}
$kategorite = Kategoria::with("termat")->get();