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

标签 php mysql laravel laravel-5.8

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

这是来自 Controller 的存储代码:

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 $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp

关于php - 如何显示我存储在数组中的 ID 详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59729157/

相关文章:

php - 如何使用mysql implode while循环

php - 如何从mysql查询中排除表?

java - flyway mysqldump 迁移

php - MySQL获取上述两个日期变量之间/之上的记录

php - 你如何在 Laravel 的 json 响应中返回一个 View ?

php - PDO 值递增 PHP、Mysql

php - 从视频中获取缩略图图像不适用于 PHP 和 ffmpeg (Ubuntu)

php - 找到出现次数最多的值并按其排序

php - 无法下载 packagist 404 未找到

php - 如果达到 div 高度,则强制将内容放到新的打印页面上