I get why foreach is not clear to me the value?

0 like 0 dislike
6 views
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
by | 6 views

1 Answer

0 like 0 dislike
You chase foreach if in this situation is
Branch::find($request->input('filter')['branch'])
In this case, ONE row is returned, not an array of results.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked Apr 13, 2019 by dimka_shaman
0 like 0 dislike
1 answer
asked May 21, 2019 by anton99zel
110,608 questions
257,186 answers
0 comments
33,854 users