在“ where”中使用变量时,数据不会显示在View中

时间:2018-08-15 09:24:14

标签: php laravel laravel-5 view eloquent

我基于foreach(时间)嵌套Event以显示Jam

这是我的控制器:

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);
}

这是我的观点:

@extends('layouts.app')
@section('content')
    <br>
    <div class="container">
        <div class="col-md-1"></div>
        <div class="col-md-8">
            <h2><b>Schedule: {{\Carbon\Carbon::parse($date)->format('j F Y')}}</b></h2>
            @foreach($jams as $jam)
                <h3><b>Jam {{$jam["waktu"]}}</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>{{$event["no_rek"]}}</td>
                        </tr>
                        <tr>
                            <td>Nama Debitur</td>
                            <td>{{$event["title"]}}</td>
                        </tr>
                        <tr>
                            <td>Tanggal Lunas KPR</td>
                            <td>{{$event["tgl_lunas"]}}</td>
                        </tr>
                        <tr>
                            <td>No. ILS</td>
                            <td>{{$event["ils"]}}</td>
                        </tr>
                        <tr>
                            <td>No. ID Laporan</td>
                            <td>{{$event["id_laporan"]}}</td>
                        </tr>
                        <tr>
                            <td>Tanggal Ambil</td>
                            <td>{{$event["tgl_ambil"]}}</td>
                        </tr>
                        <tr>
                            <td>Dokumen</td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>No. HP</td>
                            <td>{{$event["telp"]}}</td>
                        </tr>
                    </table>
                    <div class="col-md-10">Created at // by //</div>
                    <button class="btn btn-primary btn-sm">RESCHEDULE</button>
                    <br>&nbsp;
                    @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

This is my Events DB

This is the result

但是,当我尝试将@foreach($events->where('jam','LIKE', "%$temp%")->get() as $event)更改为@foreach($events->where('jam','LIKE', "%$09.15 - 09.30%")->get() as $event)时,它实际上一直都在显示... here

1 个答案:

答案 0 :(得分:0)

尝试一下:

Event::where('start_date','LIKE', '%' . $date . '%');