Insert current date time in a column using Laravel

Updated at 04-Mar-2022, By samar

Insert current date time in a column using Laravel

Hello everyone, in this post we will look at how to solve "Insert current date time in a column using Laravel" in programming.

You can insert current data time in a column of database table while creating a record in Laravel using Carbon::now(); method.
  • Get current date and insert in a column of table using carbon in Laravel

    //Import Carbon and pass the current datetime to a specific field which you want to update or insert.
    use Carbon\Carbon;
    $date = Carbon::now();
    
    //You can insert above value in created_at column of users table while updating the logged is user information.
    $user = Auth::user();
    $user->updated_at = $date;
    $user->save();
    

Back to code snippet queries related laravel