optimus
optimus

Reputation: 148

How can I show Id details which i stored in a array?

I save some id in a array using PHP implode method. I showed that array value using explode method. But I want to show that Id details. Ex: Title, Image . How can i do that?

here is store code from 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');
}

Here is, What i send to the index using route

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

Here is the Index what i show from the array:

<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

Upvotes: 2

Views: 124

Answers (1)

optimus
optimus

Reputation: 148

Just written this simple line on my code and it works.

@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp

Upvotes: 2

Related Questions