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

我正在做一个名为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 显示整行。为此,我使用以下查询:

但标题图像显示如下

http://img3.mukewang.com/62ecce520001325d05700181.jpg

我怎样才能在没有任何括号的情况下获得标题,图像和其他员工?



潇潇雨雨
浏览 126回答 2
2回答

aluckdog

经过几次研究,我修复了它。答案如下:@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