Support the ongoing development of Laravel.io →
Database Eloquent

I have a server running php 5.3.22. When I make a call to an eloquent model I get an error:

$email = Email::with('recipient')->where('token', '=', $data['token'])->firstOrFail();

I get this error: Call to undefined method Illuminate\Database\Query\Builder::firstOrFail()

When I try this on my other server running php 5.4.23 it works fine. Is this a known issue with php? I imagine that what's happening is that the where() part of the chain is returning an instance of Illuminate\Database\Query\Builder which of course doesn't have a firstOrFail() method. But why is this happening? It should be returning an instance of Eloquent.

Last updated 2 years ago.
0

This actually seems to be an issue with the version of Laravel. My local dev server was running 4.1.18 and the production 4.1.22. v4.1.22 is causing the error, but when I downgrade to 4.1.18 the error goes away. Is this a known issue in 4.1.22?

Last updated 2 years ago.
0

use ->get() method at last. $email = Email::with('recipient')->where('token', '=', $data['token'])->firstOrFail()->get();

or

use ->get() method at last. $email = Email::with('recipient')->where('token', '=', $data['token'])->first()->get();

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.