Skip to content

Laravel Request exists() vs has() vs filled() difference

PHP Dasun Kalupahana 326 views

<?php

use Illuminate\Http\Request;

// Request: ?name=&age=0&city
public function show(Request $request)
{
    $request->has('name');      // true  (key present, value is "")
    $request->exists('name');   // true  (alias of has)
    $request->filled('name');   // false (value is empty)

    $request->has('age');       // true
    $request->filled('age');    // true  (0 counts as filled)

    $request->has('country');   // false (key not sent)
    $request->missing('country'); // true

    $request->hasAny(['name', 'country']); // true (at least one key is present)
}

exists() is an alias of has(), and both only check that the key was sent, even when its value is empty or null. Use filled() when you need a non-empty value and missing() when the key must be absent.

Learn more on the blog

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.