A
A
Alexander2017-10-17 14:20:15
Laravel
Alexander, 2017-10-17 14:20:15

How to make such a query to the database?

There is a table of services and payment for the service, you need to find all the services that fit the parameters, and then select from these services only those that have made the payment.

$services = \DB::table('services_to')
            ->whereRaw('json_contains(categoriesId, \''.$categoryId.'\')')
            ->where('active', '=', 'Y')
            ->where('moderate', '=', 'Y')
            ->leftJoin('services_pay', function ($join)
            {
                $join->on('services_pay.service_id', '=', 'services_to.id')
                    ->where('pay_date', '<', strtotime(date('Y-m-d H:i:s')))
                    ->where('finish_date', '>', strtotime(date('Y-m-d H:i:s')));
            })
            ->take(20)
            ->get();

I make such a request, and it pulls all the where conditions in join

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Rogov, 2017-10-17
@RogovP

Remove all Where under Join ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question