Please Help me. I start with laraavel .Thanks so much

  laravel, php

When I search by time at page 1:

image 1

When I click page 2:

image 2

At blade

<div class="col-md-3">
    <div class="form-group">
        <label>Date range:</label>

        <div class="input-group">
            <div class="input-group-addon">
                <i class="fa fa-calendar"></i>
            </div>
            <input type="text" class="form-control pull-right" id="reservation" name="searchByTime">
        </div>
    </div>
</div>

At controller:

$searchByTime = $request->searchByTime;

if ($searchByTime != "") {
    $searchByTime = explode('-', $searchByTime);
    $timeStart = strtotime($searchByTime[0]);
    $timeStart = date('Y-m-d', $timeStart);
    var_dump($timeStart);

    $timeEnd = strtotime($searchByTime[1]);
    $timeEnd = date('Y-m-d', $timeEnd);
    var_dump($timeEnd);
    $categories = NewsCategory::whereBetween('created_at', [$timeStart.' 00:00:00', $timeEnd.' 23:59:59'])
        ->paginate(5);

    $categories->appends([
        'searchByShow' => $searchByShow,
        'searchByTime' => $searchByTime,
    ]);
}

Source: Laravel

Leave a Reply