There is a code
public function index(Request $request) { $user = Auth::user()->id; $arr = []; $branch = Branch::where('user_id', $user)->get(); $direction = direction::where('user_id', Auth::user()->id)->get(); $execute = Execute::where('user_id', Auth::user()->id)->get(); $branchCheckout = $request->input('filter')['branch'] ? Branch::find($request->input('filter')['branch']) : $branch; foreach ($branchCheckout as $key => $value){ if ($request->input('filter')['branch']){ $room = $branchCheckout->rooms()->get(); } else { $room = Branch::find($value->id)->room()->get(); } foreach ($room as $index => $item){ $arr[$key]['id'] = $value->id; $arr[$key]['name'] = $value->name; $arr[$key]['room'][$index] = ['id' => $item->id, 'name' => $item->name]; } } $clients = Client::where('user_id', Auth::user()->id)->get(); $date = ['hour' => ['8','9','10','11','12','13','14','15','16','17','18','19','20','21'], 'minute' => ['00','30']]; $schedule = Schedule::where('user_id', $user)->with(['directions', 'clients', 'executes'])->get(); return view('schedule.index', [ 'title' => 'Schedule', 'schedule' => $schedule, 'branch' => $branch, 'directions' => $direction, 'executes' => $execute, 'clients' => $clients, 'arr' => collect($arr), 'date' => collect($date), 'checkoutDate' => $request->input('filter')['date'] ? $request->input('filter')['date'] : date('d M Y') ]); }
The variable
$branchCheckout
I shows the data that I need which comes from the table value.
But somehow, when you iterate through the array
foreach ($branchCheckout as $key => $value){
Then I gets the next value as $key = incrementing a value of true. What I don't understand why it's so frustrating
This is the case when $request->input('filter')['branch'] Comes