• 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

Symfony redirect if already loggedin from login page

Laravel Collections. Is there some kind of assertStructure method?

Remove country code from phone number?

how to sort by a custom appended relation to model

Artisan, creating tables in database

How to use React Router with Laravel?

passwordless LDAP login and get user information using Kerberos ticket in PHP

Can't find vendor/autoload.php for Ratchet

How to validate Envato Purchase Code in PHP

How to create a scheduler application in php

Increase value by 1 on button click

Access denied for user 'homestead'@'localhost' (using password: YES)

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Using PHP to connect to a remote MSSQL database

About Contact Privacy policy Terms and conditions