Thursday, March 9, 2017

Laravel insert a bigint into mysql wrong

this is my table struct

SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+07:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

DROP TABLE IF EXISTS `merchants`;
CREATE TABLE `merchants` (
`id` bigint(20) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`work_hour` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

My model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
* @property $name
* Class Merchant
* @package App
*/
class Merchant extends Model
{

/**
 * The table associated with the model
 * @var string
 */
protected $table = "merchants";

//
protected $fillable = [
    "name", "url", "address", "work_hour", "id"
];

public $incrementing = false;
}

echo PHP_INT_SIZE ;// 8 echo PHP_INT_MAX ; // 9223372036854775807

Everytime, I insert new record with ID is a bigint, It always wrong in DB

$merchant->id = $newId1;
$merchant->name = $request->name;
$merchant->url = $request->url;
$merchant->address = $request->address;
$merchant->work_hour = 'a';
$merchant->created_at = date('Y-m-d h:i:s');
$merchant->updated_at = date('Y-m-d h:i:s');

$merchant->save();

$newId1 = 4550103638072627879; but it display in mysql -2144066090

Please help



via anhduc.bkhn

Advertisement