【问题标题】:laravel 5.2 return int from mysql onlylaravel 5.2 仅从 mysql 返回 int
【发布时间】:2016-10-08 05:09:39
【问题描述】:

Laravel 5.2 从 MySQL 中的任何表单字段返回 int 值。比如我有一个varchar格式的大数6271403119这个方法:

static public function gawUser($userid = null, $filed = 'id')
{
    if (Empty($userid)) $userid = Auth::user()->id;
    $user = Gaw_user::where('user_id', $userid)->first();

    if (!empty($user)) return $user->$filed;
    else return false;
    }
}

返回 2147483647

【问题讨论】:

  • 您的代码有一个额外的大括号...

标签: php mysql laravel-5.2


【解决方案1】:

确保您的 Gaw_user 模型禁用了递增,否则 eloquent 会假定您的 id 是一个自动递增的整数。

class Gaw_user extends Eloquent
{
    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;


    ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 2016-11-21
    • 2017-01-20
    • 2016-09-24
    • 2017-03-17
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多