I called model() on the HTTP request and the method does not exist

I called model() on the HTTP request and the method does not exist

Laravel 13.44 adds FormRequest model(), modelOrFail(), and models(), plus whenTransactionRunsLongerThan(). A plain Request throws BadMethodCallException, and a subclass that already defines model() still fatals on 13.45.0. Nested arrays in models() change on that tag.

· 9 min read #laravel #php #form-requests #eloquent #database

 13.43 has no InteractsWithModels. 13.44 adds the methods. 13.45 drops nested arrays

Caption: InteractsWithModels.php is 404 on v13.43.0. The file hash matches on v13.44.0 and v13.44.1. v13.45.0 keeps the public methods and filters nested arrays before findMany().

Introduction

The 25 Nov post left these APIs alone. I am writing this on 2 Dec 2026 (2026-W49). The queue row is 2026-W48, priority 7, the lowest undone item. Nothing is tagged 2026-W49. Laravel News covered form-request model lookups and whenTransactionRunsLongerThan() on 25 Nov 2026 as 13.44. Packagist this morning is v13.45.0, published 1 Dec 2026. I read tags v13.43.0 through v13.45.0. I did not boot.

About the feature

model(), modelOrFail(), and models() live on Illuminate\Foundation\Http\Concerns\InteractsWithModels. FormRequest uses that trait. Illuminate\Http\Request does not. The trait reads $this->input($key), so the query string and the body are one bag. This is not route model binding.

model() returns null, and does not query, when modelIdentifier() is null. That is isNotFilled($key) or an array. isEmptyString() treats missing, '', and whitespace as empty. A boolean skips that check (is_bool), so false is filled. An array is also filled, and is_array($id) still forces null.

modelOrFail() does not return early. It calls whereKey() on that identifier, then firstOrFail(). Empty or array input becomes whereKey(null). If nothing matches, firstOrFail() throws ModelNotFoundException. setModel() with no ids sets No query results for model [{class}].

models() is the list. On v13.45.0, modelIdentifiers() drops any value that is_array, then findMany() runs. findMany([]) returns newCollection() and does not call whereKey(). A missing key is (array) null, which is [], so the same empty collection comes back. models() does not throw for a missing key.

guessModelClass() chops _ids or _id, singularizes, then studly-cases the name. It prefers {namespace}Models\{Name} when that class exists, otherwise {namespace}{Name}, and then calls ::query(). The docs example resolves user_id to App\Models\User. A closure passed to where() is grouped before the ids. The trait does not check a policy.

DB::whenTransactionRunsLongerThan() is forwarded to the default connection. A plain number is milliseconds. startedAt is stored only on TransactionBeginning at level 1. The handler runs after the outer commit or rollback when that millisecond duration is greater than the threshold. A listener attached after the begin never sees it, so startedAt stays null.

 model() is on FormRequest. A plain Request throws BadMethodCallException

Caption: Empty or array input makes model() return null before a query. modelOrFail() still calls whereKey(). models() on 13.45 drops nested arrays, and an empty list never reaches whereKey().

Why I picked it

The archive screen posts project_ids from checkboxes. There is no route parameter to bind. The 25 Nov post only noted issue #62632. This lab is the trait and whenTransactionRunsLongerThan(). PR #62662 would have moved the helpers to __call. Taylor closed it on 27 Nov 2026. It is not in the 13.45.0 notes. The public method is still there.

Where it can be used

I would call these helpers from a form request that assigns one user, or from a bulk action with a flat id list. The closure is where team_id stays on the query. Without it, any existing id loads.

I would register the hook once in AppServiceProvider::boot(). It is not the 11 Nov slow-job hook, and the database docs still only show whenQueryingForLongerThan().

Benefit

Both APIs ship inside laravel/framework. v13.45.0 composer.json is the same bytes as v13.44.0 and v13.44.1. php is ^8.3. conflict is still laravel/horizon below 5.47.0, plus tightenco/collect below 5.5.33. replace sets illuminate/http and illuminate/database to self.version. I do not composer require either one.

FormRequest.php and Connection.php match from 13.44.0 through 13.45.0. InteractsWithModels.php matches on 13.44.0 and 13.44.1, then changes on 13.45.0. On 13.43.0 the trait is 404. The only Request.php diff I read on 13.45.0 is prefetch() splitting Sec-Purpose on ;. That is not model().

I would bump to 13.45.0. Packagist still lists 13.44.1 from 24 Nov. I requested https://laravel-news.com/laravel-13-45-0 on 2 Dec 2026 and got a 404. The 13.44 article is the one from 25 Nov.

 laravel/framework 13.45.0 replaces illuminate/http and illuminate/database

Caption: php is ^8.3. Horizon older than 5.47.0 will not solve. The model helpers and the transaction hook are methods on this package, not extra Composer requirements.

Practical example from a recent application

If composer show laravel/framework still says 13.43.x, stop. The trait is not on that tag.

composer show laravel/framework | sed -n '1,8p'
# name     : laravel/framework
# versions : * v13.45.0

Failure I hit if the controller type-hints Illuminate\Http\Request. The docs samples use $request->model(...). Macroable::__call throws. The message in that trait is:

BadMethodCallException: Method Illuminate\Http\Request::model does not exist.

The fix is the form request, which uses the trait. model('user_id') with no class guesses App\Models\User when that class exists.

Failure I hit if this form request already defines model(). The signature on v13.45.0 is still model($key, $modelClass = null, ?Closure $callback = null). Issue #62632 reports the fatal as soon as the class loads:

PHP Fatal error: Declaration of StorePostRequest::model() must be compatible with Illuminate\Foundation\Http\FormRequest::model($key, $modelClass = null, ?Closure $callback = null)

The issue was closed on 25 Nov 2026 because Laravel Nova was patched, not because 13.45.0 removed the method. FormRequest.php is the same bytes on 13.44.0, 13.44.1, and 13.45.0. I did not load a subclass. Rename the app helper. This is not a CVE.

Failure I hit if the checkbox name is project_ids[0][]. On 13.44.1, models() passes the raw array to findMany(). An integer key goes through whereIntegerInRaw(), which flattens and casts to int, so a nested id can still resolve. A string key hits whereIn(), and a multi-element nested array throws InvalidArgumentException: Nested arrays may not be passed to whereIn method. On 13.45.0 those nested arrays are dropped first. If nothing flat remains, findMany([]) returns an empty collection and does not query. The fix is a flat project_ids[] list. I did not submit the form.

use App\Models\Project;
use Illuminate\Foundation\Http\FormRequest;

class ArchiveProjectsRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'project_ids' => ['required', 'array'],
            'project_ids.*' => ['integer'],
        ];
    }

    public function projects()
    {
        return $this->models('project_ids', Project::class, function ($query) {
            $query->where('team_id', $this->user()->team_id);
        });
    }
}

project_ids.* => integer refuses a string before the lookup. A missing id on modelOrFail('user_id', User::class) throws ModelNotFoundException with No query results for model [App\Models\User].

Failure I hit if I register the transaction hook inside DB::transaction(). The begin already happened, so startedAt stays null and the handler returns on commit. Register it in the provider. The comparison is >, so a duration equal to the threshold does not call the handler. I did not open a transaction.

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

public function boot(): void
{
    DB::whenTransactionRunsLongerThan(200, function ($connection, $event, $duration) {
        Log::warning('Slow transaction', [
            'connection' => $connection->getName(),
            'event' => $event::class,
            'duration_ms' => $duration,
        ]);
    });
}

Same 13.44 tags, not this screen. Postgres lockForNoKeyUpdate() emits for no key update. MySQL and MariaDB emit for update. SQLite and SQL Server emit no lock clause, and lock() still calls useWritePdo(). migrate --schema-only skips the migration run, and loadSchemaState() still bails when migrations have already run, on SQL Server, or when the dump is missing.

 The timer starts only if the listener is attached before the outer begin

Caption: Nested begins do not store startedAt. The handler runs after the outer commit or rollback, and only when the millisecond duration is greater than the threshold.

Conclusion

What I would keep: laravel/framework at 13.45.0, ArchiveProjectsRequest::projects() calling models() with the team closure, and a flat project_ids[] list. Any older model() on a form request gets renamed before the bump. The slow-transaction log stays in AppServiceProvider::boot() with a millisecond threshold. Horizon on that app is 5.47.0 or newer.

Did you hit the same wall?

I got stuck on BadMethodCallException: Method Illuminate\Http\Request::model does not exist. after type-hinting the HTTP request, and on PHP Fatal error: Declaration of StorePostRequest::model() must be compatible when the form request already had a model() method. Did you hit the same thing — a nested project_ids[0][] that makes models() return an empty collection on 13.45.0, a transaction hook registered inside DB::transaction() that never logs, or whereIn throwing Nested arrays may not be passed to whereIn method on 13.44.1? Tell me in the comments. I read them.

Need this done on your server?

I deploy and harden Laravel/CodeCanyon apps on cPanel or VPS, and offer monthly Server Watch retainers. Hire for deploy · Care plan

References

  • Laravel 13.x HTTP requests, retrieved 2 Dec 2026. "Retrieving Model Input Values" shows model(), modelOrFail(), models(), the _id / _ids guess, and a closure that is grouped before the ids are applied: https://laravel.com/docs/13.x/requests
  • Laravel 13.x database, retrieved 2 Dec 2026. The page documents DB::whenQueryingForLongerThan() and does not mention whenTransactionRunsLongerThan(): https://laravel.com/docs/13.x/database
  • Laravel 13.x queries, retrieved 2 Dec 2026. The page documents lockForUpdate() and does not mention lockForNoKeyUpdate(): https://laravel.com/docs/13.x/queries
  • Laravel 13.x migrations, retrieved 2 Dec 2026. The page does not mention --schema-only: https://laravel.com/docs/13.x/migrations
  • Laravel News, 25 Nov 2026, "Form Request Model Lookups and PHP 8.6 Support in Laravel 13.44". The article shows model('user_id', User::class), CarbonInterval::seconds(15) for the transaction hook, and links PRs #62523 and #62423: https://laravel-news.com/laravel-13-44-0
  • PRs #62523, #62576, #62631 (merged 25 Nov 2026, in the 13.45.0 notes), #62423, #62544, #62535. Issue #62632, opened 24 Nov 2026, closed 25 Nov 2026 via Laravel Nova. PR #62662 was closed 27 Nov 2026 and is not in the 13.45.0 release notes.
  • Tags v13.43.0 through v13.45.0. InteractsWithModels.php SHA-256 is 644007dcad204e787c3aa0790220abef8d1245dd3576683d3ba828bd5d878ad2 on 13.44.0 and 13.44.1, and 0f30676ab298d471dfd6bd5de81c02092ee9a849c96dc83aa2de9b8bb1b977f9 on 13.45.0. It is absent on 13.43.0. Connection.php and composer.json match on 13.44.0, 13.44.1, and 13.45.0 (composer.json 425e6401875981434f0df8d078c913a99729a213ae0fbf245f7a25f46323de3c). Packagist v13.45.0 time 1 Dec 2026 17:10:21 UTC, published-time 17:10:33 UTC, dist d511e1f6376ba37d2de4bd30cefc4acbd1b800ea. GitHub release published 17:12:18 UTC. v13.44.1 dist 8a8c4a84852869e13190d89f9da873cd9a70f14c, time 24 Nov 2026 16:10:06 UTC, published-time 16:10:17 UTC: https://packagist.org/packages/laravel/framework
  • v13.45.0 require includes php: ^8.3. replace sets illuminate/http and illuminate/database to self.version. Conflict: laravel/horizon below 5.47.0. Connection.php SHA-256 on those three tags is ea3e6fc85c67d289caa25bfde3bb324d6809f30f38f51098178c3d28de5a945a. No CVE number is claimed here.
Share:

Get new posts in your inbox

No spam. One short email per new article — practical PHP, Laravel, devops, and AI-assisted workflows.

Comments

Powered by GitHub Discussions via Giscus. A free GitHub account is required.