Monday, 26 July 2021

Laravel Fatal error: Class 'StdClass' not found

In Laravel or php when we use to create a generic empty class, especially in Laravel then we need to include the namespace of stdclass.


For example:
// create a new object.
$dataObj = new stdClass();


If we run the above code in Laravel then we will get the error message


Laravel Fatal error: Class 'StdClass' not found


Solution:
On the top of the page Include


use \stdClass


Also if we add a backslash something like below


$Obj = new \stdClass();


In either of the above cases, it will work without any issue.

No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...