简体   繁体   中英

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?

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

或者

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM