Laravel 5.8 Eloquent Create()返回错误的ID

问题描述 投票:0回答:1
public function up() {
        Schema::create( 'active_stocks', function ( Blueprint $table ) {
            $table->bigIncrements( 'id' );
            $table->string( 'sku' );
            $table->text( 'title' )->nullable()->default( '' );
            $table->integer( 'cost' )->default(0);
            $table->integer( 'qty' )->default(0);
            $table->string( 'stock_tracking' )->default('')->nullable();
            $table->integer( 'type' )->default(1);
            $table->text( 'image' )->nullable();
            $table->integer( 'user_id' );
            $table->integer( 'status' )->default(1);
            $table->timestamps();
        } );
        \Illuminate\Support\Facades\DB::statement( "ALTER TABLE `active_stocks` AUTO_INCREMENT = 9999999999;" );
    }

我已将自动增量设置为我在开发中想要的一些值。然后我使用Laravel Eloquent创建一个新记录

$create = App/ActiveStock::create(
 [
    'sku'            => $item_array['sku'],
    'qty'            => $item_array['qty'],
    'stock_tracking' => $item_array['tracking'],
    'type'           => ActiveStock::TYPE_IMPORTED,
    'cost'           => $item_array['cost'],
    'user_id'        => $user_id,
 ]
)

echo $create->id; //Should be 9999999999

但是我得到了这个2147483647,但是我查看了数据库,id值为9999999999,这是正确的。

我在这里想念的东西。

这是$ create的完整响应

App\ActiveStock Object
(
    [fillable:protected] => Array
        (
            [0] => sku
            [1] => title
            [2] => cost
            [3] => qty
            [4] => stock_tracking
            [5] => type
            [6] => image
            [7] => user_id
            [8] => status
        )

    [connection:protected] => mysql
    [table:protected] => active_stocks
    [primaryKey:protected] => id
    [keyType:protected] => int
    [incrementing] => 1
    [with:protected] => Array
        (
        )

    [withCount:protected] => Array
        (
        )

    [perPage:protected] => 15
    [exists] => 1
    [wasRecentlyCreated] => 1
    [attributes:protected] => Array
        (
            [sku] => test-B00MSOIUOO
            [qty] => 11
            [stock_tracking] => 
            [type] => 1
            [cost] => 112
            [user_id] => 1
            [updated_at] => 2020-02-08 17:12:38
            [created_at] => 2020-02-08 17:12:38
            [id] => 2147483647
        )

    [original:protected] => Array
        (
            [sku] => test-B00MSOIUOO
            [qty] => 11
            [stock_tracking] => 
            [type] => 1
            [cost] => 112
            [user_id] => 1
            [updated_at] => 2020-02-08 17:12:38
            [created_at] => 2020-02-08 17:12:38
            [id] => 2147483647
        )

    [changes:protected] => Array
        (
        )

    [casts:protected] => Array
        (
        )

    [dates:protected] => Array
        (
        )

    [dateFormat:protected] => 
    [appends:protected] => Array
        (
        )

    [dispatchesEvents:protected] => Array
        (
        )

    [observables:protected] => Array
        (
        )

    [relations:protected] => Array
        (
        )

    [touches:protected] => Array
        (
        )

    [timestamps] => 1
    [hidden:protected] => Array
        (
        )

    [visible:protected] => Array
        (
        )

    [guarded:protected] => Array
        (
            [0] => *
        )

)
php laravel laravel-5 eloquent laravel-5.8
1个回答
0
投票

2147483647是32位有符号整数的最大值。

© www.soinside.com 2019 - 2024. All rights reserved.