Aronaman
1 month ago
186
5
Laravel

collection pass blade

Posted 1 month ago by Aronaman

Hyy guys Any trick or tip This my code

      $lists=Booking::with('localreservation')->where('approve_date',null)
                                       ->where('booked_by',$auth )
                                       ->whereDate('updated_at',$toDay)
                                       
                                       ->get();
      $groups=$lists->groupBy('validation_code')->toArray();
 dd($groups

output

array:3 [▼
  "vN9-2020-02-20" => array:1 [▼
    0 => array:31 [▼
      "id" => 7
      "bookable_type" => "App\Room"
      "bookable_id" => 2
      "local_reservation_id" => 46
      "name" => null
      "email" => null
      "booked_by" => "37"
      "user_id" => null
      "no_date" => 1
      "quantity" => 0
      "check_in" => "2020-02-27 00:00:00"
      "check_out" => "2020-02-28 00:00:00"
      "discount" => "0.05"
      …..
    ]
  ]
  "azZ-2020-02-20" => array:1 [▶]
  "KrB-2020-02-20" => array:3 [▶]

What I am try to do is for each blade

<table id="check_balance" class="display nowrap" style="width:100%">
  
  <thead>

   <tr>

     <th>No</th>

     <th>Date</th>

     <th>Name</th>
   
     <th>Phone No</th>

     <th>Types</th>

     <th>Booked By</th>

     <th>User Account</th>

      <th>Payed Amount</th>

      <th>Refund Amount</th>

     <th>Net</th>

    <th width="280px">Action</th>

    <!--  <th width="280px">Action</th> -->

   </tr>
</thead>

  
 <tbody>
 @foreach ($groups as $key => $group)

$BookingIds=$group->pluck('id');
$first=$group->first();
$types=$group->pluck('bookable');
<!-- ->flatten()->pluck('slug') -->
$implodeTypes=$types->implode('slug', ', ');

$payedAmount=$group->pluck('pay')->sum();
$refundAmount=$group->pluck('fund')->sum();
    <tr>
      <td>{{ ++$i }}</td>
      <td>{{$first->updated_at}}</td>


      <td>{{$first->localreservation->full_name}}</td>

      <td>{{$first->localreservation->phone_no}}</td>

      <td>{{$implodeTypes}}</td>
      <td>{{$first->booked_by}}</td>
      <td>{{$first->localreservation->localUserBankAccount}}</td>
      <td>{{$payedAmount}}</td>
      <td>{{$refundAmount}}</td>
      
      <td>{{$payedAmount-$refundAmount}}</td>

      <td>

         <a class="btn btn-primary" href="{{ route('local.approve',$BookingIds) }}">Approve</a>

      </td>
      
    </tr>
     @endforeach
  </tbody>

The problem is eloquent and collects query not used in blade, any suggestion, please!!

Please sign in or create an account to participate in this conversation.