aleks_lv
Новичок
Доброго
есть табличка
и отношения соответственно
модель Company
модель Rating
почему не работает сортировка по полю rating
Спасибо!!!
есть табличка
Код:
CREATE TABLE `company_rating` (
`id` int(11) NOT NULL,
`company_id` int(10) UNSIGNED DEFAULT NULL,
`rating_id` int(10) UNSIGNED DEFAULT NULL,
`rating` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`sroc` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`vip` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
модель Company
Код:
//рейтинг
public function ratings()
{
return $this->belongsToMany(\App\Model\Rating::class)
->withPivot('sroc','vip','rating','updated_at');
}
Код:
public function companies()
{
return $this->belongsToMany(\App\Model\Company::class)
->withPivot('sroc','vip','rating','updated_at');
}
Код:
$rating=Rating::find($id);
$companies=$rating->companies()
->orderBy('company_rating.rating', 'DESC')
->get();