• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Eloquent insert id with sequence next value

phplaravellaravel-5.3


PHP Snippet 1:

$billing->id = DB::getPdo()->lastInsertId(); // + 1 ?

PHP Snippet 2:

$nextval=DB::select(DB::raw("SELECT nextval('".(new Billing())->getTable()."_id_seq') as seq"))[0]->seq;

$billing = new Billing;

$billing->id = $nextval;
$billing->companyname = $request->companyname;
// ...

$billing->save();

Related Snippets

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

MISSING UPDATES FOR: MEDIA Drupal 9

Upgrade PHP on AWS Linux

laravel sanctum Route [login] not defined

str_replace or preg_replace random number from string

Convert every two values of an associative array into key-value pairs

Laravel Nova, route not found

How to Install Composer Require doctrine/dbal

Creating Combinations of Elements

PHP: PDO + CSV export not downloading (headers issue?)

PHP 8.1: strftime() is deprecated

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

Shortcode or PHP inside a shortcode in Wordpress

WordPress Security Standards want me to escape my html, but how to do it correctly?

Laravel Carbon throws error The format separator does not match

About Contact Privacy policy Terms and conditions