I need to check if schedules_id
equal to request schedules_id
then need to check profile
'booked' or 'pending' then need to pass all the 'booked' profile
seat
values into blade.php. How can i do that or if another way or logic to do this please suggest me i'm new to laravel
how i getting data now :
class PassengersController extends Controller
{
public function booking(Request $request)
{
//river is used to pass important params with flow of it from page to page
$seat = $request->seat;
$buses_id = $request->buses_id;
$schedules_id = $request->schedules_id;
$data = Buses::where('buses_id', $buses_id)->first();
$seat = json_decode($data->seat_layout, true);
$front = json_decode($data->front_layout, true);
$bookingSeat = Bookings::whereColumn('schedules_id', 'schedules_id')->get();
$bookingSeat = $bookingSeat->map(function ($bookSeat) {
$bookSeat->seat = explode(",", $bookSeat->seat);
return $bookSeat;
});
return view('frontend.booking', ['seat' => $seat, 'buses_id' => $buses_id, 'schedules_id' => $schedules_id, 'front' => $front, 'bookingSeet' => $bookingSeat]);
}
}
blade.php
<div class="bus">
@foreach($seat as $key => $item)
@foreach($bookingSeet as $seer)
<div class="col-md-1">
<div class="seats back seats
@if(in_array($item['name'], $seer['seat']))
activeSeat
@endif"
data-id="{{$key}}">
<div class="special-attributes"></div>
@if(isset($item['name'])){{$item['name']}}@else 11A @endif
<input type="checkbox" name="seat_id[]" id="{{$key}}" value="{{$key}}">
</div>
</div>
@endforeach
@endforeach
</div>
table
bookings_id users_id schedules_id buses_id routes_id seat price profile
1 1 6 1 3 1 Null pending
2 1 6 1 3 2 Null booked
3 1 6 1 3 3 null booked
Problem with my current code is getting 2 array with all bookings table column how to pass that value into blade, when i try i getting duplicated checkbox for ex. one bus have a 50 seat but now showing 100 seat. seats like 1,1,2,2 in view
One array look like this :
Collection {#426 ▼
#items: array:2 [▼
0 => Bookings {#431 ▼
#fillable: array:7 [▶]
#primaryKey: "bookings_id"
#connection: "mysql"
#table: null
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:10 [▼
"bookings_id" => 1
"users_id" => 1
"schedules_id" => 6
"buses_id" => 1
"routes_id" => 3
"seat" => "1"
"price" => null
"profile" => "pending"
"created_at" => "2019-04-09 00:00:00"
"updated_at" => "2019-04-09 00:00:00"
]
#original: array:10 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
1 => Bookings {#432 ▶}
]
}