我正在做一个名为FUND的crud,在那里我可以使用PHP内爆方法存储很多东西以及数组。在那个数组中,我存储了一些基金Id。下面是数组创建代码:<div class="custom-checkbox"> <label for="receive[]">Select Receive Funds</label> @foreach($funds as $fund) <div class="custom-control custom-checkbox"> <input class="custom-control-input" type="checkbox" name="receive[]" id="{{$fund->id}}" value="{{$fund->id}}"> <label for="{{$fund->id}}" class="custom-control-label">{{$fund->title}}</label> </div> @endforeach以下是商店代码:public function store(Request $request){ $request->validate([ 'title'=>'required', 'image'=>'required', 'description', 'available'=>'required', 'buy'=>'required', 'account', 'receive', ]); $image = $request->file('image'); $new_name = rand() . '.' . $image->getClientOriginalExtension(); $image->move(public_path('funds'), $new_name); $form_data = array( 'title'=>$request->title, 'image'=>$new_name, 'description'=>$request->description, 'available'=>$request->available, 'buy'=>$request->buy, 'buyrate'=>$request->buyrate, 'sellrate'=>$request->sellrate, 'account'=>$request->account, 'receive'=>implode(',', (array)($request->receive)), ); Fund::create($form_data); return redirect('/admin/fund');}我使用PHP分解方法在我的索引页上显示该数组。$receive=[];foreach($funds as $fund){ $receive = explode(",",$fund->receive);}正如我所提到的,我正在将基金ID存储在该数组中。因此,我想使用基金 ID 显示整行。为此,我使用以下查询:但标题图像显示如下我怎样才能在没有任何括号的情况下获得标题,图像和其他员工?
2 回答
aluckdog
TA贡献1847条经验 获得超7个赞
经过几次研究,我修复了它。答案如下:
@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp
@foreach($receives as $r)
<a href="/multi" class="list-group-item">
<p>
<img src="{{ $r->image_url }}" width="32px" height="32px"> {{ $r->title }}
<span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
<small>Reserve: {{ $r->available }}<br>Exchange rate: {{ $r->buyrate }}</small>
</span>
</p>
</a>
@endforeach
料青山看我应如是
TA贡献1772条经验 获得超8个赞
而不是括号尝试使用标签,就像我在下一个示例中所做的那样;
<img src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...
如果到图像的路由是好的,它应该有效。如果您在此之后遇到任何其他问题,请告诉我:)
- 2 回答
- 0 关注
- 123 浏览
添加回答
举报
0/150
提交
取消