I make nested foreach
to show Event
based on Jam
(Time).
This is my Controller:
public function viewEvent($date){
$events = Event::where('start_date','LIKE', "%$date%");
$hari = Carbon::parse($date)->format('l');
//Generate Hari
if ($hari == "Monday"){
$hari = "senin";
} elseif ($hari == "Tuesday"){
$hari = "selasa";
} elseif ($hari == "Wednesday"){
$hari = "rabu";
} elseif ($hari == "Thursday"){
$hari = "kamis";
} elseif ($hari == "Friday"){
$hari = "jumat";
} elseif ($hari == "Saturday"){
$hari = "sabtu";
} else{
$hari = "minggu";
}
$jams = Jam::all();
return view('cco.view_event')->with('events', $events)->with('date', $date)->with('jams', $jams)->with('hari', $hari);
}
This is my View:
@extends('layouts.app')
@section('content')
<br>
<div class="container">
<div class="col-md-1"></div>
<div class="col-md-8">
<h2><b>Schedule: </b></h2>
@foreach($jams as $jam)
<h3><b>Jam </b></h3>
<br>
@php
$count = 0;
$temp = $jam["waktu"];
@endphp
@foreach($events->where('jam','LIKE', "%$temp%")->get() as $event)
<table class="table table-bordered table-responsive">
<tr>
<td class="col-md-4">No. Rekening</td>
<td></td>
</tr>
<tr>
<td>Nama Debitur</td>
<td></td>
</tr>
<tr>
<td>Tanggal Lunas KPR</td>
<td></td>
</tr>
<tr>
<td>No. ILS</td>
<td></td>
</tr>
<tr>
<td>No. ID Laporan</td>
<td></td>
</tr>
<tr>
<td>Tanggal Ambil</td>
<td></td>
</tr>
<tr>
<td>Dokumen</td>
<td></td>
</tr>
<tr>
<td>No. HP</td>
<td></td>
</tr>
</table>
<div class="col-md-10">Created at // by //</div>
<button class="btn btn-primary btn-sm">RESCHEDULE</button>
<br>
@php
$count = $count+1;
@endphp
@endforeach
@if($count == 0)
<h4><i>No Schedule</i></h4>
@endif
<br><br>
@if($jam[$hari] == 0 || $count >= $jam[$hari])
<i>You can't add more schedule</i>
@else
<button class="btn btn-success">+ Add New Schedule</button>
<br><br>
@endif
@endforeach
</div>
</div>
@endsection
But, when I try to change @foreach($events->where('jam','LIKE', "%$temp%")->get() as $event)
to @foreach($events->where('jam','LIKE', "%$09.15 - 09.30%")->get() as $event)
, it's actually show up in all times... here
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire