Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 选择Postgres UUID';拉威尔街_Postgresql_Laravel_Uuid - Fatal编程技术网

Postgresql 选择Postgres UUID';拉威尔街

Postgresql 选择Postgres UUID';拉威尔街,postgresql,laravel,uuid,Postgresql,Laravel,Uuid,我在Postgres上有一个表,当我ddCustomer::all()时,它会自动生成UUID在Laravel上,我得到了一个带有“cs_id”=>“d0402be5-e1ba-4cb2-a80c-5340b406e2c3”的数组,这很好。当我循环或选择一条只有cs_id的记录时,它会为表中当前的三条不正确的记录返回0,2,5的数据 编辑: 论拉威尔 $customerData = Customer::where('cs_id','d0402be5-e1ba-4cb2-a80c-5340b406

我在Postgres上有一个表,当我dd
Customer::all()时,它会自动生成UUID在Laravel上,我得到了一个带有
“cs_id”=>“d0402be5-e1ba-4cb2-a80c-5340b406e2c3”
的数组,这很好。当我循环或选择一条只有cs_id的记录时,它会为表中当前的三条不正确的记录返回0,2,5的数据

编辑:

论拉威尔

$customerData = Customer::where('cs_id','d0402be5-e1ba-4cb2-a80c-5340b406e2c3')->first();

dd($customerData['cs_id']);

使用
Customer::findOrFail('d0402be5-e1ba-4cb2-a80c-5340b406e2c3')

获取与该pk匹配的记录


我假设你有
使用App\Customer

使用
客户::findOrFail('d0402be5-e1ba-4cb2-a80c-5340B40E2C3')

获取与该pk匹配的记录


我假设你有
使用App\Customer

出于某种原因,雄辩的语言在上面会弄糟

只要添加一个getter,并在需要cs_id时使用它

public function getGuid()
{
    return $this->attributes['cs_id'];
}

不知什么原因,雄辩的人在那里搞砸了

只要添加一个getter,并在需要cs_id时使用它

public function getGuid()
{
    return $this->attributes['cs_id'];
}

要使用数据库自动生成的UUID,请按如下方式定义模型:

class Customer extends Model
{
    // rename the id column (optional)
    protected $primaryKey = 'cs_id';

    // tell Eloquent that your id is not an integer
    protected $keyType = 'string';

    // do NOT set $incrementing to false
}
然后,您可以像使用经典ID一样使用所有Eloquent的方法:

$customerData = Customer::findOrFail('d0402be5-e1ba-4cb2-a80c-5340b406e2c3');

要使用数据库自动生成的UUID,请按如下方式定义模型:

class Customer extends Model
{
    // rename the id column (optional)
    protected $primaryKey = 'cs_id';

    // tell Eloquent that your id is not an integer
    protected $keyType = 'string';

    // do NOT set $incrementing to false
}
然后,您可以像使用经典ID一样使用所有Eloquent的方法:

$customerData = Customer::findOrFail('d0402be5-e1ba-4cb2-a80c-5340b406e2c3');

请提供代码请提供代码