Farshad
Farshad

Reputation: 2000

Receive values in request helper as integer in laravel

I have a form with a select tag that I am sending data into my laravel blade like below :

 <form action="{{ route('shop.products.index', $product->url_key) }}" method="get">
                        <select style=" font-family: IranSansLight, sans-serif; width:100%" class="mdb-select md-form" name="color_id">
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                        </select>
                        <input type="submit" value="send">
                    </form>

and I receive it in the same page as below :

request()->get('color_id')

The problem is this is receiving the data as string but I need the values to be an integer, so how can I get the integer or convert them to integer?

Upvotes: 0

Views: 4278

Answers (2)

Serhii Korneliuk
Serhii Korneliuk

Reputation: 87

Use

$colorId = request()->integer('color_id');

See in framework code.

Upvotes: 1

Anar Rzayev
Anar Rzayev

Reputation: 360

$colorId = (int)request()->get('color_id');

OR

$colorId = intval(request()->get('color_id'))

Upvotes: 1

Related Questions