Laravel Error Knowledge Base

Paste an exception message to find it. Every entry was reproduced by running the code shown, on real installs of Laravel 10, 11, 12 and 13, and the fix was run too. Messages are copied from those runs, not written from memory.

Scope: 16 common framework errors, run with PHP 8.3, sqlite :memory:. Database wording is driver specific, so MySQL and PostgreSQL messages differ from the sqlite text shown. HTTP-level behaviour (CSRF, auth, middleware) was not tested. See also the Compatibility Explorer.

Method ... Collection::save does not exist

BadMethodCallException

Method Illuminate\Database\Eloquent\Collection::save does not exist.

Likely causes

  • Calling a model method (save, update, delete on one record) on the Collection returned by get() or all().
  • A query that should return one model used get() instead of first().

Fix (executed and confirmed)

get() returns a Collection; loop with each() or use first() for one model

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; } }
namespace {
$cap = db(); $cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
App\Models\Post::create(['title' => 'a']);
$e = tryit(fn() => App\Models\Post::where('title', 'a')->get()->save());
$posts = App\Models\Post::where('title', 'a')->get(); $posts->each(fn($p) => $p->update(['title' => 'b']));
out($e, App\Models\Post::first()->title === 'b', 'get() returns a Collection; loop with each() or use first() for one model');
}

Docs: Eloquent collections

Property [x] does not exist on this collection instance

Exception

Property [title] does not exist on this collection instance.

Likely causes

  • Reading a model attribute from a Collection returned by get() instead of from one model.

Fix (executed and confirmed)

use first() for one model, or pluck('title') for the values

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; } }
namespace {
$cap = db(); $cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
App\Models\Post::create(['title' => 'a']);
$e = tryit(fn() => App\Models\Post::all()->title);
out($e, App\Models\Post::first()->title === 'a', 'use first() for one model, or pluck(\'title\') for the values');
}

Docs: Eloquent collections

Target [Interface] is not instantiable

Illuminate\Contracts\Container\BindingResolutionException

Target [App\Contracts\Mailer] is not instantiable.

Likely causes

  • A class type-hints an interface or abstract class and nothing is bound to a concrete class in the container.

Fix (executed and confirmed)

bind interface to implementation

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Contracts { interface Mailer {} }
namespace App\Mail { class SmtpMailer implements \App\Contracts\Mailer {} }
namespace {
$c = new Illuminate\Container\Container();
$e = tryit(fn() => $c->make(App\Contracts\Mailer::class));
$c->bind(App\Contracts\Mailer::class, App\Mail\SmtpMailer::class);
out($e, $c->make(App\Contracts\Mailer::class) instanceof App\Mail\SmtpMailer, 'bind interface to implementation');
}

Docs: Binding interfaces to implementations

Target class [X] does not exist

Illuminate\Contracts\Container\BindingResolutionException

Target class [App\Service\Billing] does not exist.

Likely causes

  • The class name is misspelled, its namespace is wrong, or it is not autoloadable (run composer dump-autoload).

Fix (executed and confirmed)

corrected namespace resolves

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Services { class Billing {} }
namespace {
$c = new Illuminate\Container\Container();
$e = tryit(fn() => $c->make('App\Service\Billing')); // wrong namespace (Service vs Services)
$ok = $c->make('App\Services\Billing') instanceof App\Services\Billing;
out($e, $ok, 'corrected namespace resolves');
}

Docs: Resolving from the container

Unresolvable dependency resolving [Parameter ...]

Illuminate\Contracts\Container\BindingResolutionException

Unresolvable dependency resolving [Parameter #0 [ <required> string $apiKey ]] in class App\Gateway

Likely causes

  • A constructor needs a scalar (string, int) that the container cannot guess and no default or contextual binding exists.

Fix (executed and confirmed)

contextual binding for the primitive

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App { class Gateway { public function __construct(public string $apiKey) {} } }
namespace {
$c = new Illuminate\Container\Container();
$e = tryit(fn() => $c->make(App\Gateway::class));
$c->when(App\Gateway::class)->needs('$apiKey')->give('k_test');
out($e, $c->make(App\Gateway::class)->apiKey === 'k_test', 'contextual binding for the primitive');
}

Docs: Automatic injection

SQLSTATE ... no such table

Illuminate\Database\QueryException

SQLSTATE[HY000]: General error: 1 no such table: posts (Connection: default, Database: :memory:, SQL: select * from "posts")

Likely causes

  • Migrations have not been run against this database (common in tests without RefreshDatabase or with a different sqlite file).
  • The model $table name does not match the migration.

Fix (executed and confirmed)

create the table (run the migration), then queries work

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. The message differs between versions:

  • Laravel 10: SQLSTATE[HY000]: General error: 1 no such table: posts (Connection: default, SQL: select * from "posts")
  • Laravel 11: SQLSTATE[HY000]: General error: 1 no such table: posts (Connection: default, SQL: select * from "posts")
  • Laravel 12: SQLSTATE[HY000]: General error: 1 no such table: posts (Connection: default, Database: :memory:, SQL: select * from "posts")
  • Laravel 13: SQLSTATE[HY000]: General error: 1 no such table: posts (Connection: default, Database: :memory:, SQL: select * from "posts")
Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; } }
namespace {
$cap = db();
$e = tryit(fn() => App\Models\Post::all());
$cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
App\Models\Post::create(['title' => 'a']);
out($e, App\Models\Post::count() === 1, 'create the table (run the migration), then queries work');
}

Docs: Running migrations

Unsupported cipher or incorrect key length

RuntimeException

Unsupported cipher or incorrect key length. Supported ciphers are: aes-128-cbc, aes-256-cbc, aes-128-gcm, aes-256-gcm.

Likely causes

  • APP_KEY is empty or the wrong length for the configured cipher.

Fix (executed and confirmed)

use a 32-byte key for AES-256-CBC (php artisan key:generate)

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
$e = tryit(fn() => new Illuminate\Encryption\Encrypter('short-key', 'AES-256-CBC'));
$k = Illuminate\Encryption\Encrypter::generateKey('AES-256-CBC');
$enc = new Illuminate\Encryption\Encrypter($k, 'AES-256-CBC');
out($e, $enc->decryptString($enc->encryptString('hi')) === 'hi', 'use a 32-byte key for AES-256-CBC (php artisan key:generate)');

Docs: Encryption configuration

Attempted to lazy load [rel] on model but lazy loading is disabled

Illuminate\Database\LazyLoadingViolationException

Attempted to lazy load [comments] on model [App\Models\Post] but lazy loading is disabled.

Likely causes

  • Model::preventLazyLoading() is on and a relation was read without being eager loaded (an N+1 query).

Fix (executed and confirmed)

eager load with with(): no lazy load happens

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models {
 class Comment extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; }
 class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; public function comments() { return $this->hasMany(Comment::class, 'post_id'); } }
}
namespace {
$cap = db(); $s = $cap->schema();
$s->create('posts', function ($t) { $t->id(); $t->string('title'); });
$s->create('comments', function ($t) { $t->id(); $t->integer('post_id'); $t->string('body'); });
App\Models\Post::create(['title' => 'a']); App\Models\Comment::create(['post_id' => 1, 'body' => 'c']);
Illuminate\Database\Eloquent\Model::preventLazyLoading(true);
App\Models\Post::create(["title" => "b"]); $p = App\Models\Post::get()->first();
$e = tryit(fn() => $p->comments->count());
$p2 = App\Models\Post::with("comments")->get()->first();
out($e, $p2->comments->count() === 1, 'eager load with with(): no lazy load happens');
}

Docs: Preventing lazy loading

Add [col] to fillable property to allow mass assignment

Illuminate\Database\Eloquent\MassAssignmentException

Add [title] to fillable property to allow mass assignment on [App\Models\Post].

Likely causes

  • create() or fill() was given an attribute that is not in $fillable (or is in $guarded), with strict mass-assignment handling.

Fix (executed and confirmed)

add the column to $fillable

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { public $timestamps = false; } class Article extends \Illuminate\Database\Eloquent\Model { public $timestamps = false; protected $fillable = ['title']; protected $table = 'posts'; } }
namespace {
$cap = db(); $cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
$e = tryit(fn() => App\Models\Post::create(['title' => 'x']));
out($e, App\Models\Article::create(['title' => 'x'])->title === 'x', 'add the column to $fillable');
}

Docs: Mass assignment

The GET method is not supported for route X. Supported methods: POST

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

The GET method is not supported for route submit. Supported methods: POST.

Likely causes

  • The URL exists, but only for other HTTP methods, for example a form route opened in the browser.

Fix (executed and confirmed)

send the request with the verb the route declares (or declare a GET route)

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
$events = new Illuminate\Events\Dispatcher; $c = new Illuminate\Container\Container; $router = new Illuminate\Routing\Router($events, $c); $c->singleton(Illuminate\Routing\Contracts\CallableDispatcher::class, fn($c) => new Illuminate\Routing\CallableDispatcher($c));
$router->post('/submit', fn() => 'posted');
$e = tryit(fn() => $router->dispatch(Illuminate\Http\Request::create('/submit', 'GET')));
$r = $router->dispatch(Illuminate\Http\Request::create('/submit', 'POST'));
out($e, $r->getContent() === 'posted', 'send the request with the verb the route declares (or declare a GET route)');

Docs: Basic routing

No query results for model [Model] id

Illuminate\Database\Eloquent\ModelNotFoundException

No query results for model [App\Models\Post] 99

Likely causes

  • findOrFail, firstOrFail or route model binding found no row with that key.

Fix (executed and confirmed)

find() returns null; or catch ModelNotFoundException / use firstOrFail in a route to get a 404

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; } }
namespace {
$cap = db(); $cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
$e = tryit(fn() => App\Models\Post::findOrFail(99));
out($e, App\Models\Post::find(99) === null, 'find() returns null; or catch ModelNotFoundException / use firstOrFail in a route to get a 404');
}

Docs: Not found exceptions

NOT NULL constraint failed: table.column

Illuminate\Database\QueryException

SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: posts.title (Connection: default, Database: :memory:, SQL: insert into "posts" default values)

Likely causes

  • An insert omitted a non-nullable column that has no default.

Fix (executed and confirmed)

supply the value, or make the column nullable()/give it a default()

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. The message differs between versions:

  • Laravel 10: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: posts.title (Connection: default, SQL: insert into "posts" default values)
  • Laravel 11: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: posts.title (Connection: default, SQL: insert into "posts" default values)
  • Laravel 12: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: posts.title (Connection: default, Database: :memory:, SQL: insert into "posts" default values)
  • Laravel 13: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: posts.title (Connection: default, Database: :memory:, SQL: insert into "posts" default values)
Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models { class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; } }
namespace {
$cap = db(); $cap->schema()->create('posts', function ($t) { $t->id(); $t->string('title'); });
$e = tryit(fn() => App\Models\Post::create([]));
out($e, App\Models\Post::create(['title' => 'x'])->title === 'x', 'supply the value, or make the column nullable()/give it a default()');
}

Docs: Column modifiers

Call to undefined relationship [rel] on model

Illuminate\Database\Eloquent\RelationNotFoundException

Call to undefined relationship [comments] on model [App\Models\Post].

Likely causes

  • with() or load() named a relation method that the model does not define.

Fix (executed and confirmed)

define the comments() relationship method on the model

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
namespace App\Models {
 class Comment extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; }
 class Post extends \Illuminate\Database\Eloquent\Model { protected $guarded = []; public $timestamps = false; }
 class PostFixed extends Post { protected $table = 'posts'; public function comments() { return $this->hasMany(Comment::class, 'post_id'); } }
}
namespace {
$cap = db(); $s = $cap->schema();
$s->create('posts', function ($t) { $t->id(); $t->string('title'); });
$s->create('comments', function ($t) { $t->id(); $t->integer('post_id'); $t->string('body'); });
App\Models\Post::create(['title' => 'a']);
$e = tryit(fn() => App\Models\Post::with('comments')->get());
out($e, App\Models\PostFixed::with('comments')->get()->count() === 1, 'define the comments() relationship method on the model');
}

Docs: Defining relationships

Route [name] not defined

Symfony\Component\Routing\Exception\RouteNotFoundException

Route [login] not defined.

Likely causes

  • route() or redirect()->route() used a name that no route has been given with ->name().

Fix (executed and confirmed)

name the route: ->name('login')

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
$events = new Illuminate\Events\Dispatcher; $router = new Illuminate\Routing\Router($events);
$request = Illuminate\Http\Request::create('/');
$url = new Illuminate\Routing\UrlGenerator($router->getRoutes(), $request);
$e = tryit(fn() => $url->route('login'));
$router->get('/login', fn() => 'x')->name('login');
$router->getRoutes()->refreshNameLookups();
out($e, str_ends_with($url->route('login'), '/login'), 'name the route: ->name(\'login\')');

Docs: Named routes

The route X could not be found

Symfony\Component\HttpKernel\Exception\NotFoundHttpException

The route missing could not be found.

Likely causes

  • No registered route matches the request path.

Fix (executed and confirmed)

declare the route (and clear route cache: php artisan route:clear)

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
$events = new Illuminate\Events\Dispatcher; $c = new Illuminate\Container\Container; $router = new Illuminate\Routing\Router($events, $c); $c->singleton(Illuminate\Routing\Contracts\CallableDispatcher::class, fn($c) => new Illuminate\Routing\CallableDispatcher($c));
$e = tryit(fn() => $router->dispatch(Illuminate\Http\Request::create('/missing', 'GET')));
$router->get('/missing', fn() => 'here');
out($e, $router->dispatch(Illuminate\Http\Request::create('/missing', 'GET'))->getContent() === 'here', 'declare the route (and clear route cache: php artisan route:clear)');

Docs: Fallback routes

Please provide a valid cache path

InvalidArgumentException

Please provide a valid cache path.

Likely causes

  • The compiled view directory (storage/framework/views) is missing, or view.compiled resolves to an empty path.

Fix (executed and confirmed)

the compiled view path (storage/framework/views) must exist and be writable

Verified on

laravel/framework 10.50.5, laravel/framework 11.57.2, laravel/framework 12.74.0, laravel/framework 13.44.1. Identical message on every version.

Reproduction and fix code (PHP, as executed)
<?php
$e = tryit(fn() => new Illuminate\View\Compilers\BladeCompiler(new Illuminate\Filesystem\Filesystem, ''));
$dir = sys_get_temp_dir() . '/views'; @mkdir($dir);
$ok = (new Illuminate\View\Compilers\BladeCompiler(new Illuminate\Filesystem\Filesystem, $dir)) instanceof Illuminate\View\Compilers\BladeCompiler;
out($e, $ok, 'the compiled view path (storage/framework/views) must exist and be writable');

Docs: Directory configuration

Spotted a wrong entry? Email info@laravelquestions.com.

Our network