1
0
Files
helper_laravel/migration.md
2026-03-16 13:58:09 +00:00

19 lines
894 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Справка по файлу миграции
### Объединение 2х таблиц
Пример для объединения двух таблиц по внешнему и внутреннему ключу.
В примере *user_id* создается в текущей таблицы и ссылается на поле *id* в таблице **User**
```php
$table->foreignId('user_id')->constrained()->onDelete('cascade');
```
Тоже самое, что и выше, но укзывается детально какие столбцы ссылаются на какую таблицу
```php
$table->unsignedBigInteger('user_id')->nullable(); // Определяем внешний id
$table->foreign('user_id')->references('id')->on('users'); // Указываем что поле user_id ссылается на id в таблице users
```