0

How would I achieve this SQL query in Laravel's eloquent?

"SELECT * FROM `cardfields` 
WHERE cardfields.id NOT IN (select fieldassociation.field_id 
from fieldassociation where fieldassociation.card_id = $cardid)"

1 Answer 1

2

To use Eloquent you need models with some relationships between the models (when models are created) but if you use QueryBuilder then you may do it using something like this:

DB::table('cardfields')->whereNotIn('id', function($query) use($cardid) {
    $query->select('field_id')
          ->from('fieldassociation')
          ->where('card_id', $cardid);
})
->get();

Make sure you import the DB using use keyword or use \DB instead of DB.

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.