himak

himak

@himak
Bratislava, Slovakia

Pracujem ako web dizajnér a programujem ako fullstack PHP/Laravel web developer.

Jun 8, 2022

Spojenie viacerych tabuliek podla ID v Models

himak odpovedal v téme Spojenie viacerych tabuliek podla ID v Models

Mas tabulku s nazvom Tabs, v ktorej evidujes udaje z inych tabuliek a teda:

Tabs id order_id employee_id file_id

Napr. pre relacny vztah 1:N (One To Many) v modeli Tabs si dopln kod:

public function orders()
{
  return $this->hasMany(Order::class);
}
public function employees()
{
   return $this->hasMany(Employee::class);
}
public function files()
{
  return $this->hasMany(File::class);
}

A potom mozes zavolat v TabControlleri

return Tabs::first()->with(‘orders’, ‘employees’, ‘files’);

A poprepaja ti vsetky tabulky.