Support the ongoing development of Laravel.io →
posted 8 years ago
Database

i have a query like this:

$sql = Trip::select('*')
            ->from('trips as t')
            ->join('trip_types as tt', 'tt.id', '=', 't.trip_type')
            ->leftJoin('seo_table as s', 's.ref_id', '=', 't.id')
            ->where('t.id', '=', $id)
            ->where('s.ref_id', '=', 'trip') <!--this statement should only run is seo_table has data-->
            ->get()->first();

i want {where('s.ref_id','=','trip')} to execute only if there is data on "seo_table"

how can this be done?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

amrshakya amrshakya Joined 9 May 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.