1

I've joined a users table using hasOne in the Laravel Model. I'd like to use the where statement on the joined table data. Is this possible using Eloquent ORM?

    $episode = Episode::where('uri', Input::get('episode'))
                        ->where('public', true, 'OR') // Return public or:
                        ->where('user.id', $->id) // Own user events
                        ->first();



    $episode = Episode::where('uri', Input::get('episode'))
                        ->where('public', true, 'OR') // Return public or:
                        ->user()->where('id', $id) // Own user events
                        ->first();
Ben
  • 4,301
  • 6
  • 37
  • 61

1 Answers1

1

I found the answer in Laravel 4.1 from this other stackoverflow question.

    $episode = Episode::where('uri', Input::get('episode'))
                        ->where('public', true, 'OR') // Return public or:
                        ->whereHas('user', function($q)
                        {
                            $q->where('id', '=', $this->user->id);

                        }) // Own user events
                        ->first();
Community
  • 1
  • 1
Ben
  • 4,301
  • 6
  • 37
  • 61