Last active
April 6, 2024 09:48
-
-
Save arvindsvt/ea0baa7e762eb39b48dffc42797ac45f to your computer and use it in GitHub Desktop.
disable-laravel-eloquent-auto-incrementcustom-primary-key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserVerification extends Model | |
{ | |
// if your key name is not 'id' | |
// you can also set this to null if you don't have a primary key | |
protected $primaryKey = 'your_key_name'; | |
public $incrementing = false; | |
// In Laravel 6.0+ make sure to also set $keyType | |
protected $keyType = 'string'; | |
} | |
https://stackoverflow.com/questions/34582535/laravel-5-2-use-a-string-as-a-custom-primary-key-for-eloquent-table-becomes-0 | |
https://stackoverflow.com/questions/45351425/how-to-disable-laravel-eloquent-auto-increment | |
protected $attributes = [ | |
'delayed' => false, | |
]; | |
https://safaetulahasan.medium.com/laravel-advance-eloquent-models-properties-for-better-code-bbfd42c755b | |
https://laracasts.com/discuss/channels/requests/problem-with-unique-field-validation-on-update | |
'code' => 'required|min:4|unique:products,code,' . $this->product->id, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment