xxxxxxxxxx
$spaceList = Space::where('user_id', $user_id)->pluck('space_id')->toArray();
$query = Interest::whereIn('space_id', $spaceList);
xxxxxxxxxx
$query = Interest::whereHas('spaces', function($query) use ($user_id) {
$query->where('user_id', '=', $user_id);
});
xxxxxxxxxx
namespace App;
use Illuminate\Database\Eloquent\Model;
class Interest extends Model
{
public function spaces()
{
// space_id is the column name in your space database table
// id the the foreign-key target, generally is the primary-key of space table
return $this->hasMany('App\Space', 'space_id', 'id');
}
}
xxxxxxxxxx
$spaceList = Space::where('user_id', $user_id)->pluck('space_id')->toArray();
$query = Interest::whereIn('space_id', $spaceList);