php - Laravel query subquery -


for example have 2 queries:

1:

$q = somecontent::select('somecontent_id')     ->where('slug', request::segment(2))     ->where('something', $something)     ->first(); 

2

$req = somecontent::select('slug')     ->where('something', $anothersomething)     ->where('somecontent_id', $q->somecontent_id)     ->first(); 

how merge these 1 query if possible in laravel's query builder? can't find lot using selects statements inside statements.

you can union them together, like

// query builder provides quick way "union" 2 queries together:  $q = somecontent::select('somecontent_id')     ->where('slug', request::segment(2))     ->where('something', $something);  $req = somecontent::select('slug')     ->where('something', $anothersomething)     ->where('somecontent_id', $q->somecontent_id)     ->union($q)->get(); 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -