© Sanjib Sinha 2017

Sanjib Sinha, Beginning Laravel, 10.1007/978-1-4842-2538-7_16

16. Eloquent Relations

Sanjib Sinha

(1)Howrah, West Bengal, India

Now we have learned to create tables through Migration and Tinker. We can also use Eloquent ORM to do the same. We also have learned to update or edit our database records. Suppose we have made three tables : ‘users’, ‘songs’, and ‘singers’. Now in our ‘songs’ table we have two table­cells, as you have probably noticed. One is ‘user_id’ and the other is ‘singer_id’. So presumably, a user inserts a song, and he has an ID. In my database I have inserted three users: first, second, and third. So they have user IDs like 1, 2, and 3, respectively.

I also inserted 10 songs, which of course have 10 respective ...

Get Beginning Laravel: A beginner's guide to application development with Laravel 5.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.