The solution I came up with is this:
$tableA = TableA::with('tableB')
->join('tableB', 'tableB.id', '=', 'tableA.tableB_id')
->where('tableA.fieldA', '=', valueA)
->where('tableB.fieldB', '=', valueB)
->orderBy('created_at', 'DESC')->paginate(10);
That join of course does affect query performance though.
Assuming you've setup one of the Eloquent relations you can use the following. http://laravel.com/docs/eloquent#querying-relations
TableA::with('tableB')
->where('fieldA', $valueA)
->whereHas('tableB', function($query)
{
// Now querying on tableB
$query->where('fieldB', $valueB);
})->orderBy('created_at', 'DESC')
->paginate(10);
Oh beautiful, that's exactly what I was looking for, thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community