Suhail
Suhail

Reputation: 1

Property [id] [details] [details] [amount] does not exist on this collection instance

On my controller take data via foreach where the $upcoming->order_id is same I am checked by dd($notes) data is show but i can't get on my view php. before I am tried $note->get('amount') method it is also not working

public function index() 
{       $upcomings = Booking_informations::Upcoming();
        $notes = [];
        foreach ($upcomings as $upcoming) {
         $notes[] = Notes :: where('order_id',$upcoming->order_id)-> orderBy('id', 'ASC')->get();
        };
       return View('upcoming',compact('upcomings','notes',)); 
}

upcoming.blade.php

<table class="table table-bordered mb-0">
  <tbody>
    @foreach($notes as $note )
      <tr>
        <th scope="row">1</th>
        <td>{{date('d-M-Y', strtotime($note->created_at))}}</td>
        <td>{{$note->details}} </td>
        <td>{{$note->amount}} </td>
      </tr>
    @endforeach
  </tbody>
</table>

I have got answer while wrote below method have any more simple way for get results..

<table class="table table-bordered mb-0">
    <thead>
    <tr>
        <th>#</th>
        <th>Date</th>
        <th>Content</th>
        <th>Amount</th>
    </tr>
    </thead>
    <tbody>
    @foreach($notes as $note )
        @foreach($note as $id )
    <tr>
        <td scope="row">1</td>
        <td>{{$id->details}} </td>
        <td>{{$id->amount}} </td>
    </tr>
        @endforeach
    @endforeach

    </tbody>
</table>

Upvotes: 0

Views: 50

Answers (1)

creativEuphoria
creativEuphoria

Reputation: 26

Try referencing $note instead of $notes in your foreach loop and see if that works.

I have also noticed that you have named your view file View.blade.php. Should this be upcoming.blade.php to match the name you have provided in the returned view? Just a thought.

Upvotes: 1

Related Questions