Laravel:字符串类型总是返回2147483647

时间:2018-07-17 07:06:09

标签: laravel api eloquent

当我通过api检索数据时,尽管我已经以字符串列类型创建了该列,但是却得到2147483647。在表中,它已成功存储989547 ****。

迁移:

$table->string('source_number',10)->unique();

控制器:

public function getSourceNumberSmsTemplate(Request $request){
    $detail=$request->all();

    if(empty($detail['source_number']) || !array_key_exists('source_number',$detail)){
        return Response::json([
        'message' => "Missing Parameters. Please recheck submitted data"], 422);
    }

    $template= smstemplate::find($detail['source_number']);
    return Response::json([
        $detail['source_number']=>$template], 200);
    }

Api结果:

{
    "id": 1,
    "user_id": 1,
    "source_number": 2147483647,
 }

2 个答案:

答案 0 :(得分:1)

尝试查询构建器:

use Illuminate\Support\Facades\DB;

$template = DB::table('sms_templates')
->where('source_number', '=' , $request->source_number)
->get();

答案 1 :(得分:-1)

尝试将其转换为模型中的bigint或字符串,默认情况下为整数'

//如下所示

protected $keyType = 'bigint';