Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Support\Str;
- use Illuminate\Database\Eloquent\Model;
- class UuidModel extends Model
- {
- /**
- * Indicates if the IDs are auto-incrementing.
- *
- * @var bool
- */
- public $incrementing = false;
- /**
- * The "type" of the auto-incrementing ID.
- *
- * @var string
- */
- protected $keyType = 'string';
- /**
- * The "booting" method of the model.
- */
- protected static function boot()
- {
- parent::boot();
- static::creating(function ($model) {
- if (empty($model->id)) {
- $model->id = (string) Str::uuid();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement