Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

public function recover(Request $request){     $email = $request->input('email');     // Create tokens     $selector = bin2hex(random_bytes(8));     $token = random_bytes(32);      $url = sprintf('%s',  route('recover.reset',['selector'=>$selector, 'validator'=>bin2hex($token)]));      // Token expiration     $expires = new DateTime('NOW');     $expires->add(new DateInterval('PT01H')); // 1 hour      // Delete any existing tokens for this user     DB::delete('delete * from password_reset where email =?', $email);      // Insert reset token into database     $insert = $this->db->insert('password_reset',          array(             'email'     =>  $email,             'selector'  =>  $selector,              'token'     =>  hash('sha256', $token),             'expires'   =>  $expires->format('U'),         )     ); 

Am trying to implement forgot password when the email form is submitted to forgotPasswordController it generates the below error

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

This is the picture of the controller the above code is not there is i cant modify it RecoverPasswordController Image

At the header i have tried using

use DateTime; 

Or

use App\Http\Controllers\DateTime 

But still generates same error please help fixing it. thanks in advance

like image 207
myckhel Avatar asked Aug 29 '18 09:08

myckhel


1 Answers

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.

like image 165
delboy1978uk Avatar answered Sep 29 '22 11:09

delboy1978uk