PhilMarc PhilMarc - 4 months ago 7
PHP Question

How to check if Laravel request has no input

I am using Laravel 4.

I am willing to display a text, only if my request contains no

input


For instance, I have a product list
mysite/products
and I have an input field to filter by price, which gives the following URL once clicked:
mysite/products?price=true


I can use
if(Input::has('price'))
to check if I have this input, but the thing is that I have a bunch of input fields, and I would like to display text only when there are no inputs.

I am thinking about something like:

@if(Input::has('price')||Input::has('mixed')||Input::has('male')||Input::has('female')||Input::has('kid')||Input::has('page'))
//Do nothing
@else
//Display my text here
@endif


But in a simplified way...

I was thinking of checking the URi with
Request::segment(1)
and see if it matches
'products'
but it does even with the inputs active.

Answer

Get all input data, and count it:

@if ( ! count(Input::all()))
  // Display text here
@endif
Comments