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

**Code:** `TypeError: Argument #1 must be of type X, Y given` · **Category:** Laravel · **Seen on:** Laravel, PHP

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/type-error-argument-must-be-of-type)
