The second parameter of whereIn should be an array of a closure. You are passing a query builder object. If you add ->get() it should work. That is not what you want. It would get that array, and you would make another query to the database. Use a closure
->whereIn('columnName', function($query){
$query->select('...')->from('...')->where('...');
})
In your case
$streetType = DB::table('streetTypes')
->select('streetType', 'id')
->whereIn('id', function($query){
$query->select('streetsTypeId')
->from('streets')
->groupBy('streetsTypeId')
->where('suburbsId', 1))
->get();
Memory is cheap, execution time is expensive.
Put the street name in the streets table. Your queries become more compex, that slows you down. You have more indexes in you database, that takes memory. I don't think street names repeat frequently enought to make it pay off.
Thanks, took your suggestion in and altered the table streets(id, suburbId, streetName). I've just done a concat of streetName and Type. Sorry i thought i answered this yesterday but for some reason mustn't have posted it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community