dongzhangnong2063 2017-02-28 19:16
浏览 74
已采纳

Laravel错误:“试图获得非对象的属性”

I have a table what populates from database:

@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

And I got this error:

ErrorException in 20d205ed160f36c734b8252e44ac81bfa0977988.php line 6: Trying to get property of non-object

If I replace the table with

<?php print_r($productdetails);?>

I got the the array with the good values.

What going wrong?

  • 写回答

2条回答 默认 最新

  • dtfpznrbn503027700 2017-03-03 12:40
    关注

    The solution was: {{ $productdetails[0]->type }}

    Thanks for @rahul_m for his answer:

    Once check the structure of array it is having 0th index first,

    You should get it like,

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

    OR

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

    Give it a try, it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏