【问题标题】:Laravel 3 - Eloquent save() is saving wrong value over and overLaravel 3 - Eloquent save() 一遍又一遍地保存错误的值
【发布时间】:2014-02-16 19:48:09
【问题描述】:

我会尽力解释我的情况。对不起,如果它没有意义,它首先真的没有意义。

我有一个使用 Laravel 3 的应用程序。我有一个模型名称 Receipt,其中包含与支付网关交易的支付历史记录。每次有人为某物付款时,都会将收据条目添加到数据库中。

收据架构

public function up() {
    Schema::table('receipts', function($table) {
        $table->create();
        $table->increments('id');
        $table->integer('individual_id')->unsigned();
        $table->integer('transaction_id')->unsigned();
        $table->decimal('amount', 6, 2);
        $table->string('account_number', 8)->nullable();
        $table->string('category', 255)->nullable();
        $table->timestamps();
    });
}
...

收据控制器片段

...
if ($response->approved) {                
    $r = new Receipt();
    $r->individual_id = $response->customer_id;
    $r->transaction_id = $response->transaction_id;
    $r->amount = $response->amount;
    $r->account_number = $response->account_number;
    $r->category = $response->description;
    $r->save();

    $url = URL::to_action('receipt@history', array($response->transaction_id));
} else {
...

我的问题是 transaction_id 没有保存正确的值。我已验证在返回的 $response->transaction_id 属性中找到了支付网关响应,但保存到 DB 字段的内容不正确。例如,假设支付网关 $response->transaction_id 是 5879971244... 每个交易 ID 保存到我的数据库中的是 4294967295。就像我有这个字段的 setter 方法,但我没有。

如果我将任意值硬编码到 $r->transaction_id,例如 1234567890,然后 $r->save() 它将很好地保存,而不是来自 $response 对象的值。

【问题讨论】:

    标签: mysql payment-gateway eloquent laravel-3


    【解决方案1】:

    看起来 Int 字段最多只允许 4294967295 这是存储在我的数据库中的内容。我将字段更改为 bar varchar。问题解决了!

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多