У меня в таблице более 50000 записей. Взаимоотношение многим.Laravel 5 красноречивый кусок данных
отчеты Модель:
public function busines(){
return $this->belongsToMany('App\Busines', 'busines_record', 'record_id', 'busines_id');
}
Busines модель:
public function records()
{
return $this->belongsToMany('App\Record', 'record_id');
}
Мой запрос:
$data = Records::with('busines')->where('show', '=', 1)->get();
Запрос давно выполнить. Как оптимизировать запрос?
Попробуйте добавить основной указатель в поле 'show'. https://laravel.com/docs/5.2/migrations#creating-indexes –