TypeError: Argument #1 must be of type X, Y given Laravel Origin: Application & API Last updated 4 Nov 2026

Laravel/PHP: TypeError: App\Services\Mailer::send(): Argument #1 ($user) must be of type App\Models\User, null given

A function received a value of the wrong type — often null where an object was required.

Exact message you may see TypeError: Argument #1 ($user) must be of type App\Models\User, null givenmust be of type string, null givenArgument 1 passed to must be an instance of, null givenTypeError: Illuminate\...::method(): Argument #2 must be of typeReturn value must be of type, null returned
Seen on: Laravel PHP

Meaning

PHP 7+/8 enforce typed parameters. The message tells you the expected and received types and the call site. Commonly a query returned null (Auth::user() for guests, find()), or string vs int from request input. Add checks, use nullable types (?User), or cast.

Common causes

  • null passed from find()/first()/Auth::user()
  • String input where int expected (strict types)
  • Wrong object type (Collection vs Model)
  • Missing return type conversion
  • Optional dependency not bound

⚡ Quick fix

  1. Guard against null before calling
  2. Type-hint as nullable if appropriate (?User)
  3. Cast request input: (int) $request->id

Detailed fix by platform

Laravel

  1. $user = $request->user() ?? abort(401);

How to diagnose

  1. Expected — Type required?
  2. Given — What arrived?
  3. Source — Where null came from?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

403 This action is unauthorized — Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized. (Laravel)403 This action is un…Array to string conversion — Warning: Array to string conversion (PHP)Array to string conve…Attempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…Cannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …Class "App\Models\X" not found — Laravel: Error: Class "App\Models\Post" not found (Laravel)Class "App\Models\X" …Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…Implicit float to int — Deprecated: Implicit conversion from float 2.5 to int loses precision (PHP)Implicit float to intLaravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…TypeError…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.