Laravel, Search by month, but I can’t find anything

  laravel, search

I’m doing a search a month, but I can’t find anything. Start is a column of type date, 2020-07-23.


public function cityName(Request $request, City $city)
    $month = $request->month;
    $status = $request->status;

    if (!empty($month)) {
       $chamado = Chamados::where('cite_id', $city->id)
                ->whereMonth('start', $month)
                ->when($status, function ($query, $status) {
                    return $query->where('status', $status);
    } else {
        $chamado = Chamados::where('cite_id', $city->id)->get();            

    $total = Chamados::where('cite_id', $city->id)->value(DB::raw('SUM(total)'));

    return view('', compact('city', 'chamado', 'total', 'month'));

My form:

<form class="form-inline mb-3" action="{{ route('', $city->id) }}" id="formSearch" method="GET">
<input type="month" class="form-control form-control-sm mr-md-2" name="month" id="month" value="{{ isset($month) ? $month : '' }}">

<button type="button" name="filter" id="filter" class="btn btn-info btn-sm mr-2 mb-2">
    <i class="fad fa-filter"></i> Filter

without search

with search

Source: Laravel StackOverflow

Leave a Reply