I would like to display a text only when my request
does not contain any input
s
At the moment, a product list is displayed on the following page: /products
. On that same page, there is a form with several inputs to filter the products.
If I filter by price, I get the following URL once the GET form is submitted: /products?price=true
I am using the following condition to check if the request has a price input: if(Input::has('price'))
This works fine, but I have several other request parameters, and I would like to display the text only when none of those inputs are filled.
This is what I have so far, it works, but it is not ideal:
@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
Is there a way to do something similar but in much simpler way?
Get all input data, and count it:
@if ( ! count(Input::all()))
// Display text here
@endif
@if (!request()->filled('price') || !request()->filled('mixed') || !request()->filled('male') || !request()->filled('female'))
// Display my text here
@endif
Before Laravel 5.4:
$request->exists
: Determine if the request contains a given input item key.
$request->has
: Determine if the request contains a non-empty value for an input item.
In Laravel 5.5:
$request->exists
: Alias for $request->has$request->has
: Determine if the request contains a given input item key.$request->filled
: Determine if the request contains a non-empty value for an input item.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With