phplaraveldatetimephp-carbon

php, conversion of string date to DateTime in request


So I currently have a request sending to a function:

$request->date

and date, in this case, is a string "2019-10-15"

The function is expecting \DateTime $scheduled as the argument this date is going to

How can I properly (using Carbon/laravel) convert this date string to dateTime in this request portion where it's being sent?


Solution

  • In your controller where you need the date, use this:

    $date = Carbon::parse($request->date);