• 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

How to submit the custom form data in database in WordPress without plugin using ajax?

PHP DOTENV unable to load env vars

VB.NET WebRequest with PHP POST

Laravel Carbon throws error The format separator does not match

PHP array sort and remove duplicates by two field values

Distribute array row data to make multiple new rows

Find out the name of the last script that included the current one

Get latest Tweets - What API

Using spatie/media-library, how to rename a collection of uploaded files?

how to check version of codeigniter framework?

Target class controller does not exist - Laravel 8

Convert date and time to Jalali in Laravel

Redirect to previous page with php

Show date difference as "20" instead of "20 years ago"

How to override htaccees file for cache control header

About Contact Privacy policy Terms and conditions