0

Heres the output to the screen if I dd() in the render method

Illuminate\Support\Collection {#1355 ▼
  #items: array:1 [▼
    0 => {#1360 ▼
      +"provider": "provider"
      +"name": "name"
      +"id": 2
      +"price": 35.0
    }
  ]
}

This is the ProductSelect Component class. ve tried...

  1. view('components.product-select',['products'=>$products]);
  2. view('components.product-select',compact('products'));
  3. view('components.product-select',['products'=>$products->toArray()]);
  4. view('components.product-select')->with(['products'=>$products->toArray()]);

and a few others

. Im confused cause the DD will send to screen.but when i was to use the variable in the view it doesn't pick it up..

 public function render()
    {
        $products = $this->products->execute(['user_id'=> $this->userid,'att_id'=>$this->attid]);
        dd($products);
        return view('components.product-select')->with(['products'=>$products]);
    }

product-select.blade here. Im trying to create another component with the output of products here..I don't think creating another component here matters because i can take out that bit of code with just an echo and nothing happens..

 <div  {{ $attributes->merge(['class' => 'modal-body row '. $classBody])}}>
      @foreach ($products as $product)
         <x-product-card
             class="w-100"
            :name="$product->name"
            :description="$product->description"
            :productid="$product->id"
            :price="$product->price"
            >
         </x-product-card>
      @endforeach
 <div {{ $attributes->merge(['class' => 'modal-footer ' . $classFoot])}}>
     {{ $buttons }}
 </div>

Any thoughts?

Quickee
  • 321
  • 1
  • 6
  • 13

1 Answers1

0

Looks like my problem was a naming issues. I was passing an action into the controller to get the data..

public $products;

public function __construct(AllowedProducts $products)
{
        $this->products = $products;
}

And then tried to reuse the variable unintentionally. This was causing the issue..

public function render()
    {
        $products= $this->products->execute(['user_id'=> $this->userid,'att_id'=>$this->attid]);
        return view('components.product-select', [
            'products' => $products,
            ]);
    }

So I changed it to $test and it worked. no need to add it to the variables in the class list. Im not sure if thats a bug. In the frame work

public function render()
    {
        $test= $this->products->execute(['user_id'=> $this->userid,'att_id'=>$this->attid]);
        return view('components.product-select', [
            'test' => $test,
            ]);
    }

Quickee
  • 321
  • 1
  • 6
  • 13