如何显示存储在数组中的ID详细信息?

问题描述 投票:2回答:1

我使用PHP implode方法将一些ID保存在数组中。我使用explode方法显示了该数组值。但我想证明一下ID的详细信息。例如:标题,图像。我怎样才能做到这一点?

这里是来自控制器的商店代码:

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');
}

这里是我使用路线发送给索引的内容

Route::get('/', function () {
$funds = DB::table('funds')->get();
$receive=[];
foreach($funds as $fund){
    $receive = explode(",",$fund->receive);
}
return view('frontend.exchangePage.exchange',['funds'=>$funds,'receive'=>$receive]);});

这是我从数组中显示的索引:

<div class="" style="{{--height: 200px; overflow: auto;--}}">
 @foreach($receive as $r)
   <a href="/multi" class="list-group-item">
      <p>
        <img src="" width="32px" height="32px"> {{  $r }}
          <span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
             <small>Reserve: 1170580 BDT<br>Exchange rate: 1 BDT = 0.98 BDT</small>
          </span>
      </p>
   </a>
 @endforeach

php mysql laravel laravel-5.8
1个回答
1
投票

只需在我的代码上写此简单的行就可以了。

@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp
© www.soinside.com 2019 - 2024. All rights reserved.