0

The below query works well in mysql but how to represent the same thing using Laravel.

select * from user_subscription where vendor_id = 'user_100' 
and 0 = (select count(*) from user_restricted_dates where vendor_id = 'user_100')

I tried with code but gives error as unknown column '0' in where clause

$list = UserSubscription::where('vendor_id', '=', $vendor_obj->vendor_id)
    ->where(0, '=', "(select count(*) from user_restricted_dates where vendor_id = 'user_100'")
    ->get();

Well the error indicates what it is but how to represent it

1 Answer 1

2

The where method of the Query Builder maps the first value you pass to a field in the model. You'd have to use the whereRaw method instead.

$list = UserSubscription::where('vendor_id', '=', $vendor_obj->vendor_id)
    ->whereRaw("0 = (select count(*) from user_restricted_dates where vendor_id = 'user_100')")
    ->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.