close

[Solved] Laravel Error “Class ‘App\Http\Controllers\DateTime’ not found”

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel Error “Class ‘App\Http\Controllers\DateTime’ not found” in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel Error “Class ‘App\Http\Controllers\DateTime’ not found” Error Occurs?

Today I get the following error Laravel Error “Class ‘App\Http\Controllers\DateTime’ not found” in php.

How To Solve Laravel Error “Class ‘App\Http\Controllers\DateTime’ not found” Error ?

  1. How To Solve Laravel Error “Class 'App\Http\Controllers\DateTime' not found” Error ?

    To Solve Laravel Error “Class 'App\Http\Controllers\DateTime' not found” Error Above your class definition, import the class with a use statement.

  2. Laravel Error “Class 'App\Http\Controllers\DateTime' not found”

    To Solve Laravel Error “Class 'App\Http\Controllers\DateTime' not found” Error Above your class definition, import the class with a use statement.

Solution 1

Add a backslash \ (to define root namespace)

$dateTime = new \DateTime();

also you can use classes

use DateTime;
use DatePeriod;
use DateInterval;

Solution 2

Above your class definition, import the class with a use statement.

use DateTime;

The alternative to that is to use the fully qualified namespace in your code. With PHP classes in the global namespace, all this means is a single backslash before the class name:

$expires = new \DateTime('NOW');

I prefer the first approach, as it allows you to see every class used in that file at a glance.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment