Posts Learn Components new Snippets new Categories Tags About

How to pass boolean in Laravel through URL

Learn how to pass boolean value in Laravel via request URL to easily allow the backend to process the value

Created on Sep 22, 2021


In Laravel, you can pass a boolean value via the URL to easily allow the backend to process a value such as a toggle or a status. To do so, you can pass either one of the "true" or "false" strings value or 1 for true and 0 for false number.

Laravel Pass in Boolean Value Via URL // true // false
Or if you prefer to use the number it will be as follows // true // false

Laravel Request Boolean

To easily get the boolean value, you can call the "boolean" method of the "Request" class and it will like below.

Request::boolean('download'); // true or false
If you resolve the Request from the dependency injection then the code will be as follows.

public function store(Request $request)
    if ($request->boolean('downloadable')) {
        // Do something

If you like our tutorial, do make sure to support us with some coffee. We need the juice to write the content during the night 🤙🏻