I am a little confused about this.
Let me put into an example. Let's say I have a table called books
{
"books": {
"id": 1,
"bookshelf_id": 1,
"created_at": "2015-10-26 08:26:32",
"updated_at": "2015-10-26 08:26:32"
}
And let's say I have another table called bookshelves
which has this.
"bookshelves": {
"id": 1,
"name": "Mrs. Maritza Pollich DVM",
"slots": 20,
}
And this is how the model looks like
book
public function bookShelf()
{
return $this->hasOne('App\Models\BookShelf');
}
bookshelf
public function book()
{
return $this->belongsTo('App\Models\Book');
}
Now this works just fine
The problem
A bookshelf
has also many books
in it as well. How Can achieve this relation(s)?
something like this will cause confusion, I assume.
Bookshelf model
public function book()
{
return $this->hasMany('App\Models\Book');
}
and book model
public function bookshelf()
{
return $this->belongsTo('App\Models\Bookshelf');
}
Is this the right way to go about it?