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

331
Views
Not work id getter in model (i use uuid type)

I make the primary key as uuid in Model.

Migration with uuid primary key:

Schema::create('brands', function (Blueprint $table) {
    $table->uuid('id')->unique()->primary();
    $table->string('title');
    $table->timestampsTz();
});

Checking model:

Psy Shell

>>> $x = App\Models\Brand::find('e025b8aa-c71e-42ca-b87c-7ee27695b83a');
=> App\Models\Brand {#720
  id: "e025b8aa-c71e-42ca-b87c-7ee27695b83a",
  title: "Batman",
  created_at: "2017-04-28 23:51:41+10",
  updated_at: "2017-04-28 23:51:41+10",
}

When accessing the model, it contains the correct data.

>>> $x->title
=> "Batman"
>>> $x->id
=> 0

Why zero?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Eloquent has some default conventions and thus has some expectations on your model, table, constraints etc... Luckily, you can change them:

From the Laravel documentation:

Primary Keys

Eloquent will also assume that each table has a primary key column named id. You may define a $primaryKey property to override this convention.

In addition, Eloquent assumes that the primary key is an incrementing integer value, which means that by default the primary key will be cast to an int automatically. If you wish to use a non-incrementing or a non-numeric primary key you must set the public $incrementing property on your model to false.

Regarding your question: "Why zero?"

Because Eloquent casts the string of "e025b8aa-c71e-42ca-b87c-7ee27695b83a" explicitly to an int value and that result is int 0...

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!