我有一个laravel 5.6查询,该查询使用单个结果填充数组以传递给视图。 这是查询:
$farms=DB::select("select pic,shop_name,StateName,amount,
duration,ror,farm_shop.id from farm_shop join states on states.id=farm_shop.state_id where
farm_shop.id=:id",['id' => $id]);
print_r
命令返回以下内容:
Array ( [0] => stdClass Object ( [pic] =>
092720180421565bac5ae4974f9MAIN.jpg
[shop_name] => Pig Farm [StateName] => STATEGTR
[amount] => 3000000 [duration] => 11 [ror] => 28 [id] => 4 ) )
我的视图像这样访问它:
@foreach($farms->as $farmshop)
<div class="row course-set courses__row col-md-6 col-offset-md-3">
@php
$pic="http://xxxxxx/storage/".$farmshop['pic'];
@endphp
<section class="col-md-3">
<img src="{{$pic}}" alt="" width="1200" height="1200" title="xxx">
<div class="text-center"><b>{{$farmshop['shop_name']}}</b><br/>
Location: {{$farmshop[['StateName']}}
<br/>
Amount (X):<span style="color:red">
<b> {{number_format($farmshop['amount'],2)}}</b></span><br/>
Period (Months): {{$farmshop['duration']}}<br/>
Rate (%): {{$farmshop['ror']}} <div class="text-
center">
<div class="col-md-12 text-center">
<a href="" class="btn btn-success btn-block">Invest</a>
</div>
<div> </div>
</div>
</section>
</div>
@endforeach
现在抛出的错误是:
未定义偏移:1
下面的行在内置的laravel函数compileForEach($ expression)中突出显示:
$iteratee = trim($matches[1]);
请问我该如何解决?。谢谢
答案 0 :(得分:0)
问题出在以下代码行:@foreach($farms->as $farmshop)
正确的代码应该是:@foreach($farms as $farmshop)
谢谢