Я использовал цикл for для извлечения запроса и возможности хранения в массиве.Массив, например, выглядит следующим образом: i:
dd ($ s);
array:2 [▼
"Block A" => array:49 [▶]
"Block K" => array:149 [▶]
]
Теперь с этими массивами у меня есть больше данных, и я хочучтобы отобразить его в поле выбора на блейде.
array:2 [▼
"Block A" => array:49 [▼
0 => array:1 [▼
"Block A0" => "1"
]
Я хочу отобразить только 1 , который находится в блоке A0 => 1
homeController.php
foreach ($v as $f ) {
$m[$i] = [
$l.$i => $f->rNum,
];
$s[$l] = $m;
$i++;
}
$s = (array_filter($s));
return view('home')->with($s);
// I have also tried with
//return view('home')->with('res',$s);
Home.blade.php
@foreach ($res as $s)
<option value="> {{_____?____}}" </option>
//I only want to display 1 to 49 here
@endforeach
Помните, что есть 2 массива, Блок A и Блок K
, поэтому в поле выбора должны быть все значения блока A (то есть: от 1 до 49) и все значения блока K (то есть: от 1 до 149) ввторое поле выбора.
Я не слишком уверен, как получить значение здесь, но, по крайней мере, я могу получить значения в контроллере
**
ПОЛНЫЙ КОД КОНТРОЛЛЕРА
public function viewHall($id){
$path = request()->path();
$substring = substr($path, 0,10);
$title;
$viewApp;
$viewroom = "";
$s[] = array();
$i = 1;
if ($substring == "view/hall/"){
$viewApp = DB::select('Select * from applications where hall = "'.$id .'" AND status = "pending"');
foreach ($viewApp as $k) {
$a[] = $k->flat;
}
$countA = (count($a));
foreach ($a as $l) {
$viewroom = DB::select('Select applications.* , residences.* , rooms.* from applications
LEFT Join residences on applications.resi = residences.resiName
LEFT JOIN rooms on rooms.resiID = residences.id
where hall = "'.$id .'" AND status = "pending" AND rooms.available = 0
AND rooms.flatName ="'.$l.'" group by rooms.flatName, rooms.roomNum');
foreach ($viewroom as $f ) {
$s[$l][$i] = [
$l => $f->roomNum,
];
$i++;
}
}
$s = (array_filter($s));
$title = "Hall (" . $id .")";
return view('admin.viewapp')->with('applications', $viewApp)->with('title',$title)->with('rid',$id)->with('rooms',$viewroom)
->with('roomNs', $s)->with('flat',$a)->with('flatc', $m);
}
elseif ($substring == "view/resi/"){
$viewApp = DB::select('Select * from applications where resi = "'.$id .'" AND status = "pending"');
$viewroom = DB::select('Select applications.* , residences.* , rooms.* from applications
LEFT Join residences on applications.resi = residences.resiName
LEFT JOIN rooms on rooms.resiID = residences.id
where resi = "'.$id .'" AND status = "pending" AND rooms.available = 0');
$title = "Residence (" . $id .")";
}
elseif ($substring == "view/year/"){
$viewApp = DB::select('Select * from applications where year = "'.$id .'" AND status = "pending"');
$viewroom = DB::select('Select applications.* , residences.* , rooms.* from applications
LEFT Join residences on applications.resi = residences.resiName
LEFT JOIN rooms on rooms.resiID = residences.id
where applications.year = "'.$id .'" AND status = "pending" AND rooms.available = 0');
$title = "Year (" . $id .")";
}
else{
$viewApp = DB::select('Select * from applications where status = "pending"');
$viewroom = DB::select('Select applications.* , residences.* , rooms.* from applications
LEFT Join residences on applications.resi = residences.resiName
LEFT JOIN rooms on rooms.resiID = residences.id
where status = "pending" AND rooms.available = 0');
$title = "View All";
}
return view('admin.viewapp')->with('applications', $viewApp)->with('title',$title)->with('rid',$id)->with('rooms',$viewroom)
-with('roomNs', $roomN);
}
**
**
Просмотр.blade.php
<form class="" action="{{URL('process/')}}" method="post">
{{ csrf_field() }}
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Hall</th>
<th scope="col">Residence</th>
<th scope="col">Year</th>
<th scope="col">Flat</th>
<th scope="col">Room</th>
<th scope="col">Status</th>
<th scope="col">Submitted on</th>
<th scope="col">Approve</th>
<th scope="col">Reject</th>
</tr>
</thead>
<tbody>
<tr>
@foreach ($applications as $show)
<input type="hidden" name="id" value="{{$show->id}}">
<input type="hidden" name="hall" value="{{$show->hall}}">
<input type="hidden" name="resID" value="{{$show->resID}}">
<input type="hidden" name="year" value="{{$show->year}}">
<input type="hidden" name="flat" value="{{$show->flat}}">
<th scope="row">{{$i}}</th>
<td>{{$show->hall}}</td>
<td>{{$show->resi}}</td>
<td>{{$show->year}}</td>
<td>{{$show->flat}}</td>
<td>
<div class="form-group">
<select class="form-control" id="roomNo" name="roomNo" required autofocus>
<option value="" selected>Select Room Number</option>
<?php $i=0; ?>
@foreach ($roomNs as $key1 => $value1)
@foreach ($value1 as $key2 => $value2)
@foreach ($value2 as $key3 => $value3)
<option value="{{ $value3 }}"> {{ $value3 }} </option>
@endforeach
@endforeach
@endforeach
</select>
</div>
</td>
<td>{{$show->status}}</td>
<td>{{$show->created_at}}</td>
<td><input type="submit" class="btn btn-primary"name="approve" value="Approve"></td>
<td><input type="submit" class="btn btn-danger"name="reject" value="Reject"></td>
</tr>
@endforeach
</tbody>
</table>
</form>
**