Advertisement
Guest User

Untitled

a guest
Aug 20th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. // получаем все простые и собираем для них инфу
  2.         $products = Product::where('type', 0)->where('type', '<>', null)->select(['products_id', 'block_id', 'manufacturers_id', 'type'])
  3.             ->whereHas('inComposite')
  4.             ->with([
  5.                 'descriptions' => function ($q) {
  6.                     $q->select(['products_name', 'products_description', 'products_id'])->where('language_id', 2);
  7.                 },
  8.                 'block' => function ($q) {
  9.                     $q->select(['block_id','block_name_uk', 'selector']);
  10.                 },
  11.                 'product_specs' => function ($q) {
  12.                     return $q->where('spec_control', '<>', 0)->select(['spec_specs.spec_name', 'spec_specs.spec_id', 'spec_control']);
  13.                 },
  14.                 'prod_spec_values' => function($q) {
  15.                     $q->where('spec_control', '<>', 0)->select(['value_name', 'spec_values.value_id','spec_values.spec_id']);
  16.                 },
  17.                 'inComposite' => function ($q) {
  18.                     $q->select(['composite_id', 'product_id']);
  19.                 },
  20.                 'manufacturer' => function ($q) {
  21.                     $q->select('manufacturers_name', 'manufacturers_id');
  22.                 },
  23.             ])->get();
  24.  
  25.  
  26. // моделька Product::
  27. public function product_specs()
  28.     {
  29.         return $this->belongsToMany(Spec::class, 'spec_products', 'product_id', 'spec_id')
  30.             ->withPivot(['spec_sort', 'spec_control'])
  31.             ->groupBy('pivot_spec_id')
  32.             ->orderBy('pivot_spec_sort');
  33.     }
  34.  
  35. public function prod_spec_values()
  36.     {
  37.         return $this->belongsToMany(SpecValue::class, 'spec_products', 'product_id', 'value_id','product_id')
  38.             ->withPivot(['sort', 'spec_control', 'image_name'])
  39.             ->groupBy('pivot_value_id')
  40.             ->orderBy('pivot_sort');
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement