• 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

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Open a popup box after receiving result from ajax

Laravel Collections. Is there some kind of assertStructure method?

(Laravel) How to delete multiple models including optional relationships?

Laravel get user data with profile

Warning: sqlite_query() expects parameter 1 to be resource, string given

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

laravel automatically deletes server.php on php artisan serve

PHP - installing Xdebug on Mac with XAMPP (Unix File)

How can I make good efficent AJAX live forms with just jQuery and

Download & Save Zoom Recording in directory by PHP

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

Laravel set default language not working

Laravel UUID generation

About Contact Privacy policy Terms and conditions