# Call to undefined method

You called a method the object does not have: a typo, a missing relation or trait, or a model method on a collection. The class in the message says where.

Message:

```text
Call to undefined method App\Models\User::subscriptions()
```

Exception:

```text
BadMethodCallException
```

## What it means

You called a method that nothing on that object defines. Models, query builders, relations and collections catch such calls and throw a `BadMethodCallException`. On a class of your own without a `__call` method, PHP itself throws an `Error` with the same wording, such as `Call to undefined method App\Services\Report::update()`. A model passes unknown calls on to its Eloquent query builder, which passes them to the base query builder. When the last one fails, each layer in `ForwardsCalls` catches the exception and throws a new one with its own class name, so a call on a model names the model: `Call to undefined method App\Models\User::subscriptions()`. The same call on a query names `Illuminate\Database\Eloquent\Builder`, on `DB::table()` it names `Illuminate\Database\Query\Builder`, and on a relation such as `$post->author()` it names `Illuminate\Database\Eloquent\Relations\BelongsTo`.

## Why it happens

- A typo, or a relation that is not defined on this model.
- A scope that is not on this model. `Post::published()` without a `published` scope on `Post` gives `Call to undefined method App\Models\Post::published()`.
- A model method called on a collection. `all()`, `get()` and `paginate()` return many models, so `User::all()->posts()` fails. Collections use the `Macroable` trait, which words it differently: `Method Illuminate\Database\Eloquent\Collection::posts does not exist.`
- A method from a trait the model does not use. `notify()` comes from `Notifiable` and `createToken()` from Sanctum's `HasApiTokens`. Without the trait, `$post->notify(...)` gives `Call to undefined method App\Models\Post::notify()`.
- A macro that has not been registered when the code runs. `collect(['a'])->toUpper()` failed with `Method Illuminate\Support\Collection::toUpper does not exist.` until `Collection::macro('toUpper', ...)` had run.

Eager loading gives its own exception. `User::with('posts')` or `$user->load('posts')` without a `posts()` method throws `Illuminate\Database\Eloquent\RelationNotFoundException` with `Call to undefined relationship [posts] on model [App\Models\User].` Laravel catches the `BadMethodCallException` from calling `posts()` and throws this one instead.

## How to fix it

For a typo, compare the name with the methods on the class the message names. For a missing relation, define it on that model:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
}
```

For a scope, define it with the `Scope` attribute on the model you query, as a protected method:

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    #[Scope]
    protected function published(Builder $query): void
    {
        $query->whereNotNull('published_at');
    }
}
```

For a collection, call the method on each model, or eager load the relation:

```php
<?php

$users = User::with('posts')->get();

foreach ($users as $user) {
    $count = $user->posts->count();
}
```

For a trait method, add the trait to the model: `use Notifiable;` for `notify()`, and `use HasApiTokens;` from `Laravel\Sanctum` for `createToken()` once Sanctum is installed.

For a macro, register it in the `boot` method of a service provider, where the docs advise, so it exists before any request, command or job uses it.

## Find it in production

With `APP_DEBUG=false`, the visitor gets a 500 "Server Error" page, and a JSON request gets `{"message": "Server Error"}`. None of `BadMethodCallException`, `RelationNotFoundException` and `Error` is on the `$internalDontReport` list in `Illuminate\Foundation\Exceptions\Handler`, so Laravel reports all three to `storage/logs/laravel.log`, and Ranetrace's [error monitoring](/features/error-monitoring) records them with the stack trace and the request they happened on.

Reproduced on Laravel 13.45, PHP 8.5, 5 December 2026.

Read more: https://laravel.com/docs/eloquent-relationships

## Related

### Terms

- [Eloquent ORM in Laravel](https://ranetrace.com/glossary/eloquent-orm-in-laravel.md)
- [Eager loading in Laravel](https://ranetrace.com/glossary/eager-loading-in-laravel.md)
- [Query scopes in Laravel](https://ranetrace.com/glossary/query-scopes-in-laravel.md)
- [Query builder in Laravel](https://ranetrace.com/glossary/query-builder-in-laravel.md)

### Other errors

- [Call to a member function on null](https://ranetrace.com/error-guides/php-call-to-a-member-function-on-null.md)

Read this guide in a browser: https://ranetrace.com/error-guides/laravel-call-to-undefined-method
