I have 3 tables: Users, Languages and Levels.
One user have many languages and level.
Example:
- Jorge speaking: English advanced, Spanish basic.
- Peter speaking: English advanced, Italian medium, French basic.
- Luis speaking: Spanish advanced, English advanced, Italian medium.
Table User
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| lastname | varchar(50) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
Table Languages
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
Table levels
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
Pivot table
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | | NULL | |
| language_id | int(11) | NO | | NULL | |
| level_id | int(11) | NO | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+-------------+----------+------+-----+---------+----------------+
The question is, how create the pivot table with three tables (in the doc laravel the example is only with 2 tables) is possible with three tables? How to relationship with eloquent?