mardi 20 mars 2018

Query all where list id has user id

I'm trying to get all the properties, in a watchlist(s) where the list has a user id.

The relationship is set up as follows.

Each watchlist is related to a user id. Each Property has a watchlist id.

I need all properties, in all the watchlists belonging to that user.

The watchlist gets the user_id automatically upon creation.

Here are my models

Watchlist

public function books(){
      return $this->hasMany('App\WatchedBooks');
    }

    public function user(){
      return $this->belongsTo('App\User');
    }

WatchedBooks

public function watchlist(){
    return $this->belongsTo('App\Watchlist');
  }

Query Gets all books in every list disregarding user ids and list ids

$Watchlists = WatchedBooks::all();

Currently gets all books regardless of userid.

I need all books in all of the user's lists.

A user could have multiple lists List A List B

So something like All books from all lists where the list id is related to user id.

This is what the Watchlist DB looks like WatchlistDB

This is what the WatchedBooks DB looks like Books in watchlist



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2pqYrP5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire