Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

joyjas77 joyjas77 Joined 17 Sep 2014

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.

© 2024 Laravel.io - All rights reserved.