Postgresql 选择Postgres UUID';拉威尔街
我在Postgres上有一个表,当我ddPostgresql 选择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
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');
请提供代码请提供代码