Как получить 4 популярных цвета?
Controller
class YarnController extends Controller
{
public function index()
{
$yarns = Yarn::where('status', 1)
->has('colors')
->orderBy('contacts', 'desc')
->get();
return view('yarn.index', compact('yarns'));
}
}
Model
class Yarn extends Model
{
protected $with = ['colors'];
public function colors()
{
return $this->hasMany(YarnColor::class)
->where('status', 1)
->orderBy('contacts', 'desc');
}
}
Как получить 4 самых популярных цвета, а не все (как сейчас)?