Just don't SELECT
id
or none of the models fields if you don't need them (where
clause will work anyway)
Car::join('models', 'cars.model_id', '=', 'models.id')
->where('models.name', 'like', '%'.$term.'%')
->paginate($_ENV['ITEMS_PER_PAGE'], ['cars.*','models.fieldsYouNeedOrNothing']);
side note: You can use whereHas()
instead of join to do it more 'eloquent' way if you really don't need joined table's fields:
Car::whereHas('models', function ($query) use ($term) {
$query->where('models.name', 'like', '%'.$term.'%');
})->paginate($_ENV['ITEMS_PER_PAGE']);
This will run subquery on models table and leave you without any worries about the keys.