У меня есть таблица, которая заполняет из базы данных:

@extends('layouts.master')
@section('main')
@parent
<table border=1 align=center;>
<tr><td rowspan=10><img src="media/productimg/question.jpg" width=250px></td>
<th>Márka</th><td colspan=3>{{ $productdetails->brand }}</td></tr>
<tr><th>Beszállító</th><td colspan=3>{{ $productdetails->supplier }}</td></tr>
<tr><th>{{ $productdetails->type }}</th>
<th colspan=3>{{ $productdetails->name }}</th></tr>
<tr><th>Nettó beszerzési ár</th><td>{{ $productdetails->wholeprice }} Ft</td>
<th rowspan=2>Ár</th><td rowspan=2>{{ $productdetails->price }} Ft</td></tr>
<tr><th>Bruttó beszerzési ár</th><td>{{ $productdetails->wholeprice }} Ft</td>
<tr><th>Vonalkód</th><td>{{ $productdetails->barcode }}</td><th>Raktáron</th><td>{{ $productdetails->count }} {{ $productdetails->dimension }}</td></tr>
<tr><th>Elhelyezkedés</th><td>{{ $productdetails->whereis }} {{ $productdetails->whereis2 }}</td><th>Küszöb</th><td>{{ $productdetails->threshold }} {{ $productdetails->dimension }}</td></tr>
<tr><th>Utolsó rendelés</th><td> NA </td>
<th>Utolsó vásárlás</th><td> NA </td></tr>
<tr><td colspan=5><a href="stock_productimageupload.php"><button class="button">Kép szerkesztése</button></a>
<a href="stock_productupdate.php"><button class="button">Termék szerkesztése</button></a>
<a href="stock_productcountupdate.php"><button class="button">Mennyiség szabályozása</button></a></td></tr>
</table>
@endsection

И я получил такую ​​ошибку:

ErrorException в 20d205ed160f36c734b8252e44ac81bfa0977988.php строка 6: попытка получить свойство необъекта

Если я заменю таблицу на

<?php print_r($productdetails);?>

Я получил массив с хорошими значениями.

Что не так?

0
Feralheart 28 Фев 2017 в 22:16

2 ответа

Лучший ответ

Решение было: {{ $productdetails[0]->type }}

Спасибо за @rahul_m за его ответ:

После проверки структуры массива сначала он имеет 0-й индекс,

Вы должны получить это как,

{{$product[0]->brand}}

ИЛИ

$product = DB::table("inventory")->where("barcode", $id)->first(); // and get data as echo $product->brand;

Попробуйте, он должен работать.

0
Feralheart 3 Мар 2017 в 12:40

Вы говорите, что массив покажет, как должно быть.

Вы можете попробовать, например:
{{ $productdetails['type'] }} вместо {{ $productdetails->type }}

Но, пожалуйста, опубликуйте результат функции print_r($productdetails), чтобы мы могли увидеть, что не так с кодом.

1
Robert 28 Фев 2017 в 19:20