1 year ago

Trying to get values from the collection

Posted 1 year ago by manshu

I am trying to create a query, but having issue. I have Listing that has 2 columns city_id and state_id. I am trying to get result where city_it = model and similar for state.

my route ={state}/{city}/

So if user tries to access some city, they will see all listings for that state. Please help. Thanks

        $state = State::where('name', $state)->get();
        $city = City::where('name', $city)->get();
        $listings = Listing::where(function ($query) use ($state, $city) {
            $query->where('city_id', $city)->get();
            $query->where('state_id', $state)->get();
        return $listings;

Please sign in or create an account to participate in this conversation.