Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
php:laravel:relations [2024/10/10 01:50] mirocowphp:laravel:relations [2024/10/10 02:37] (текущий) mirocow
Строка 15: Строка 15:
   * Полиморфный Один из Многих   * Полиморфный Один из Многих
   * Полиморфный Многие-К-Многим   * Полиморфный Многие-К-Многим
 +
 +===== Ссылки =====
 +
 +  * [[https://habr.com/ru/articles/494658/|Используем трейты для полиморфных связей]]
 +
 +===== Отношения «один к одному» =====
 +
 +{{:php:laravel:one-to-one.png?600|}}
  
 <code bash> <code bash>
Строка 20: Строка 28:
 $ Php artisan make:model Rent $ Php artisan make:model Rent
 </code> </code>
- 
-===== Отношения «один к одному» ===== 
  
 <code php> <code php>
Строка 47: Строка 53:
 ===== Отношение «один ко многим» ===== ===== Отношение «один ко многим» =====
  
 +{{:php:laravel:one-to-many.png?600|}}
  
 <code php> <code php>
Строка 107: Строка 114:
 ===== Отношения HasOneThrough и HasManyThrough ===== ===== Отношения HasOneThrough и HasManyThrough =====
  
 +{{:php:laravel:has-one-through.png?600|}}
  
-<text>+<code>
 rent rent
     id - integer     id - integer
Строка 123: Строка 131:
     name - string     name - string
     tenant_id - integer     tenant_id - integer
-</text>+</code>
          
 <code php> <code php>
Строка 167: Строка 175:
 ===== Аналогично, отношение «Has Many Through» ===== ===== Аналогично, отношение «Has Many Through» =====
  
-<text>+{{:php:laravel:has-many-through.png?600|}} 
 + 
 +<code>
 country country
     id - integer     id - integer
Строка 182: Строка 192:
     title - string     title - string
  
-</text>+</code>
  
 <code php> <code php>
Строка 256: Строка 266:
 ===== Отношение «многие ко многим» ===== ===== Отношение «многие ко многим» =====
  
-<text>+{{:php:laravel:many-to-many.png?600|}} 
 + 
 +<code>
 employees employees
     id - integer     id - integer
Строка 268: Строка 280:
     user_id - integer     user_id - integer
     role_id - integer     role_id - integer
-</text>+</code>
  
 <code php> <code php>
Строка 343: Строка 355:
 ===== Полиморфный Один к одному ===== ===== Полиморфный Один к одному =====
  
 +{{:php:laravel:one-to-one-polymorphic.png?600|}}
  
-<text>+<code>
 tenants tenants
     id – integer     id – integer
Строка 358: Строка 371:
     waterbillable_id     waterbillable_id
     waterbillable_type     waterbillable_type
-</text>+</code>
          
 <code php> <code php>
Строка 400: Строка 413:
 ===== Полиморфный Один Ко Многим ===== ===== Полиморфный Один Ко Многим =====
  
 +{{:php:laravel:one-to-many-polymorphic.png?600|}}
  
-<text>+<code>
 posts  posts 
     id – integer     id – integer
Строка 421: Строка 435:
     commentable_id – integer     commentable_id – integer
     commentable_type – string     commentable_type – string
-</text>+</code>
          
 <code php> <code php>
Строка 475: Строка 489:
  
 ===== Полиморфный Один из Многих ===== ===== Полиморфный Один из Многих =====
 +
  
  
 ===== Полиморфный Многие-К-Многим ===== ===== Полиморфный Многие-К-Многим =====
  
 +{{:php:laravel:many-to-many-polymorphic.png?600|}}
  
-<text>+<code>
 videos videos
     id – integer     id – integer
Строка 493: Строка 509:
     taggable_id – integer     taggable_id – integer
     taggable_type – string     taggable_type – string
-</text>+</code>
  
 <code php> <code php>