Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Amrith's avatar

User FindorFail returns NULL only

Dear Guys, I didn't get any exception message . what is the reason behind of it ? please help me

Please note: ID is not available on my database . its fake one.

Controller Class

var_dump(User::findOrFail(21)); //returns NULL

API Response

POST http://127.0.0.1:8000/api/auth/register

HTTP/1.1 200 OK
Host: 127.0.0.1:8000
Date: Fri, 04 Feb 2022 14:32:29 GMT
Connection: close
X-Powered-By: PHP/8.0.13
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache, private
Date: Fri, 04 Feb 2022 14:32:29 GMT
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Access-Control-Allow-Origin: *

NULL


Response code: 200 (OK); Time: 201ms; Content length: 5 bytes
0 likes
11 replies
tykus's avatar

What is User; does it extend \Illuminate\Database\Eloquent\Model (via the \Illuminate\Foundation\Auth\User class)?

Is the firstOrFail method being overridden somewhere in that class hierarchy?

Amrith's avatar

@Laralex no luck.

 User::findOrFail(200); //Return NULL

Everything is normal. i didn't change any thing

Sinnbeck's avatar

Why is null uppercase? Pretty sure php is lowercase

rodrigo.pedra's avatar

@Sinnbeck it accepts both, but PSR-2 standardized as lowercase.

Same for TRUE/true and FALSE/false.

But I think the default output for null from the interpreter is always uppercase.

Yep, just confirmed:

$ php -a
Interactive mode enabled

php > var_dump(null);
NULL
1 like
Amrith's avatar

Its my bad. mistakenly i created findOrFail custom function in model class. Sorry guys.

Apologies for it

tykus's avatar

@Amrith so, exactly like I asked 4 hours ago...

Is the firstOrFail method being overridden somewhere in that class hierarchy?

Sinnbeck's avatar

@Amrith please mark the original answer by Tykus as best to set the thread as solved

Please or to participate in this conversation.