Laravel Error "Class 'App\Http\Controllers\DateTime' not found"

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.


DateTime is a PHP Object, so you can declare it using the slash before:

new \DateTime();

Or declaring it before you use and instantiating later:

use DateTime;

class Etc
{
    public function test()
    {
        $datetime = new DateTime();
    }
}