4

According to this answer https://stackoverflow.com/a/29740218/7921383 handling Boolean values in URL is depend on framework.

How to pass Boolean values false and true in laravel?

112Legion
  • 1,129
  • 12
  • 25
  • Does this answer your question? [How to pass boolean variable of false in a URL](https://stackoverflow.com/questions/29739970/how-to-pass-boolean-variable-of-false-in-a-url) – George Willcox Feb 05 '20 at 11:09
  • It depends .... see this URL : https://stackoverflow.com/a/29740034/3110023 – iman Feb 05 '20 at 11:19

4 Answers4

11

Since version laravel/framework: v6.13. There are added ability to call on the \Illuminate\Http\Request method boolean that will return true when value is "1", "true", "on", and "yes". Otherwise, returns false.

112Legion
  • 1,129
  • 12
  • 25
6

Via a URL you could pass 1(as true) or 0(as false) for boolean values.

Chemaclass
  • 1,933
  • 19
  • 24
4

You can try this way:

http://some-url?arg=true

Or

http://some-url?arg=false

And in php:

$boolean = filter_var( $request->query('arg'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42
-1

There is a helper in laravel

Request::boolean('query-param-name')

At the end it does same thing as Dimitri Leiko described, but maybe helps other people.

 public function boolean($key = null, $default = false)
    {
        return filter_var($this->input($key, $default), FILTER_VALIDATE_BOOLEAN);
    }
  • I dislike it as using Facade is a bad thing I https://www.reddit.com/r/PHP/comments/131t2k1/laravel_considered_harmful/ – 112Legion Jul 28 '23 at 16:21