Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Selección de UUID de Postgres en Laravel

Tengo una tabla en Postgres que genera automáticamente UUID, cuando agrego Customer::all(); en Laravel obtengo una matriz con "cs_id" => "d0402be5-e1ba-4cb2-a80c-5340b406e2c3" que está bien. Cuando hago un bucle o selecciono un registro con solo el cs_id, los datos devuelven 0,2,5 para los tres registros actualmente en la tabla, que son datos incorrectos.

EDITAR:

 CREATE TABLE customers ( cs_id character varying(255) NOT NULL DEFAULT gen_random_uuid(), CONSTRAINT cs_customers_pkey PRIMARY KEY (cs_id), }

en laravel

 $customerData = Customer::where('cs_id','d0402be5-e1ba-4cb2-a80c-5340b406e2c3')->first(); dd($customerData['cs_id']);
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Por alguna razón, Eloquent se equivoca allí.

simplemente agregue un getter y utilícelo cuando necesite el cs_id

 public function getGuid() { return $this->attributes['cs_id']; }
over 4 years ago · Santiago Trujillo Report

0

Para usar uuid generados automáticamente por la base de datos, defina su modelo de la siguiente manera:

 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 }

Luego, puede usar todos los métodos de Eloquent como lo haría con las identificaciones clásicas:

 $customerData = Customer::findOrFail('d0402be5-e1ba-4cb2-a80c-5340b406e2c3');
over 4 years ago · Santiago Trujillo Report

0

Usar Customer::findOrFail('d0402be5-e1ba-4cb2-a80c-5340b406e2c3');

para obtener el registro que coincida con ese pk.

Supongo que además tienes que use App\Customer;

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!