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)"
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.