2

I'm doing a crud named FUND, where I can store many things along with a array using PHP implode method. In that array i'm storing some FUND Id. Here is array Create Code:

<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

Here is the store code:

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

I'm showing that array on my index page using PHP explode method.

$receive=[];
foreach($funds as $fund){
    $receive = explode(",",$fund->receive);
}

As I mentioned I'm storing fund id in that array. So i want to show the whole row by using the Fund ID.For that I'm using query by this:

@foreach($receive as $r)
  <a href="/multi" class="list-group-item">
    <p>
      <img src="{{$fund=\App\Fund::where(['id'=>$r])->get('image')}}" width="32px" height="32px"> {{$fund=\App\Fund::where(['id'=>$r])->get('title')}}
        <span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
          <small>Reserve: {{$fund=\App\Fund::where(['id'=>$r])->get('available')}}<br>Exchange rate: {{$fund=\App\Fund::where(['id'=>$r])->get('buyrate')}}</small>
        </span>
    </p>
  </a>

@endforeach

But the title image is showing like this Frontend View

How Can I just Get Title, Image and other staff without any bracket?

2 Answers 2

3

After several researches i fixed it. Here is the answer:

@php $receives = \App\Fund::whereIn('id', $receive)->get(); @endphp
   @foreach($receives as $r)
       <a href="/multi" class="list-group-item">
           <p>
              <img src="{{ $r->image_url  }}" width="32px" height="32px"> {{ $r->title  }}
                <span class="pull-right text text-muted hidden-xs hidden-sm" style="font-size:11px;">
                    <small>Reserve: {{ $r->available }}<br>Exchange rate: {{ $r->buyrate }}</small>
                 </span>
            </p>
         </a>
   @endforeach
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of brackets try to use the tags Like I do in the next example;

<img src="<?=$fund=\App\Fund::where(['id'=>$r])->get('image')?>"...

If the route to the image is good it should work. If you have any other problem after this tell me :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.