Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Uladzimir's avatar

How to insert 2 request years from range-inputs to Builder code?

Have a next blade code, where are 2 years "from" and "to". This is the annual range of films to be retrieved from the films table. Films from this year to this year.

<div class="year-wrapper">
    <div class="year-input">
    <div class="year-field">
        <span>year from</span>
        <input type="number" class="year-input-min" value="{{ $yearMin }}" name="year">
    </div>
    <div class="year-separator">-</div>
    <div class="year-field">
        <span>year to</span>
        <input type="number" class="year-input-max" value="{{ $yearMax }}" name="year">
    </div>
    </div>
    <div class="year-slider">
    <div class="year-progress"></div>
    </div>
    <div class="year-range-input">
    <input type="range" class="range-min" min="{{ $yearMin }}" max="{{ $yearMax - 1 }}" value="{{ $yearMin }}" step="1">
    <input type="range" class="range-max" min="{{ $yearMin + 1 }}" max="{{ $yearMax }}" value="{{ $yearMax }}" step="1">
    </div>
</div>

It looks like a range slider with two inputs "year from" and "year to"

And also have a filtering construction in Builder, which search films by year. Seems like below:

<?php

namespace App\Models\Filters\Film;

use App\Services\Filters\Filterable;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Film;

class Year implements Filterable
{

    public static function apply(Builder $builder, $value)

    {
        $builder->whereBetween('year', [1944, 1954]);
        return $builder;
    }
}

The problem is that I don't know how to replace the example-years 1944 and 1954 with variables that would intercept the values from the first and second input, respectively. None of my attempts and googling helped.

Can you tell me how to substitute variables in Builder instead of these numbers?

0 likes
1 reply
Uladzimir's avatar
Uladzimir
OP
Best Answer
Level 1

DONE. All is wery simple to fix

in blade added to every name="year" + []

        <span>year from</span>
        <input type="number" class="year-input-min" value="{{ $yearMin }}" name="year[]">
    </div>
    <div class="year-separator">-</div>
    <div class="year-field">
        <span>year to</span>
        <input type="number" class="year-input-max" value="{{ $yearMax }}" name="year[]">

in Filterable file change natural years to value[0] and value[1]

public static function apply(Builder $builder, $value)

    {
        $builder->whereBetween('year', [$value[0], $value[1]]);
        return $builder;
    }

Please or to participate in this conversation.