1

I have 3 models:

  • Book
  • Author
  • Owner

Book has:

  • id
  • name
  • photo
  • author_id
  • owner_id
  • is_available

Author has:

  • id
  • name
  • photo

Owner has:

  • id
  • name
  • photo
  • book_id

A book can have multiple Authors and Owners.

How can I store more single id in author_id and owner_id?

2
  • 3
    Why not use a common many to many relationship? How do you currently define the relations? Manually, or through Eloquent? Commented Oct 9, 2022 at 16:46
  • 4
    You don't, you use a Many To Many relationship (using a pivot table), it is basic programming/db normalization, not Laravel. Check this documentation, it will help you Commented Oct 9, 2022 at 17:20

1 Answer 1

2

If the author has many books, and the book have many authors, than it’s a many to many relationship and you will need intermediate tables author_book and owner_book. In order to be able to define many author ids for one a book and many books for one author. Check the Laravel doc here for implementation details https://laravel.com/docs/9.x/eloquent-relationships#many-to-many

Good luck.

Sign up to request clarification or add additional context in comments.

1 Comment

To be precise, following the Laravel standards naming conventions, you will need author_book and book_owner, not owner_book

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.