从 PHP 数组中获取值并显示它们

我正在做一个名为 FUND 的 crud,我可以使用 PHP implode方法在其中存储许多东西以及一个数组。在那个数组中,我存储了一些 FUND 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 explode方法在我的索引页面上显示该数组。


$receive=[];

foreach($funds as $fund){

    $receive = explode(",",$fund->receive);

}

正如我提到的,我将基金 ID 存储在该数组中。所以我想通过使用基金 ID 来显示整行。为此,我正在使用以下查询:

但是标题图片显示是这样的

http://img.mukewang.com/62da64e50001d24a05560162.jpg

如何在没有任何括号的情况下获取 Title、Image 和其他人员?



慕容3067478
浏览 133回答 2
2回答

冉冉说

经过几次研究,我修复了它。这是答案:@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp&nbsp; &nbsp;@foreach($receives as $r)&nbsp; &nbsp; &nbsp; &nbsp;<a href="/multi" class="list-group-item">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="{{ $r->image_url&nbsp; }}" width="32px" height="32px"> {{ $r->title&nbsp; }}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <small>Reserve: {{ $r->available }}<br>Exchange rate: {{ $r->buyrate }}</small>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</a>&nbsp; &nbsp;@endforeach

有只小跳蛙

尝试使用标签而不是括号就像我在下一个例子中所做的那样;<img&nbsp;src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...如果图像的路线很好,它应该可以工作。如果您在此之后有任何其他问题,请告诉我:)
打开App,查看更多内容
随时随地看视频慕课网APP