laravel insert or update using query builder and get last insert id

 $current_user = wp_get_current_user() ;
        $notes = DB::table('wp_comments')->updateOrInsert(
            ['comment_ID' => $id],
            [
                'comment_author' => $current_user->user_login,
                'comment_author_email' => $current_user->user_email,
                'comment_content' => '111163New content',
                'comment_date' => date('Y-m-d H:i:s'),
                'comment_date_gmt' => date('Y-m-d H:i:s'),
                'user_id' => $current_user->ID,
            ]
        );
        if(!$id){
            $id = DB::getPdo()->lastInsertId();
        }

        dd($notes);

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *