N
N
Nikidze2021-03-25 17:01:09
Laravel
Nikidze, 2021-03-25 17:01:09

Why laravel swears at the absence of a key in the array, but at the same time outputs it to the template?

There is code in the template:

<div>
      <img src="{{ $product['image'] }}" alt="{{ $product['title'] }}">
</div>

There is a code in the controller,
view('product')->with(['product' => (array)DB::table($category)->where('id', $id)->first(),

When I try to open the page, everything is displayed normally, but in the logs I see this:
Undefined index: image (View: /home/nikita/projects/moreustrits/resources/views/product.blade.php) Looks

like it works - don't touch it, but this makes it very difficult to look at the logs. What can be done?

cleared cache, didn't help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-03-26
@jazzus

You can use Laravel.

return view('product', ['product' => Product::find($id)]);
<img src="{{ $product->image }}" alt="{{ $product->title }}">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question