Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Support\Str;
  6. use Illuminate\Database\Eloquent\Model;
  7.  
  8. class UuidModel extends Model
  9. {
  10. /**
  11. * Indicates if the IDs are auto-incrementing.
  12. *
  13. * @var bool
  14. */
  15. public $incrementing = false;
  16.  
  17. /**
  18. * The "type" of the auto-incrementing ID.
  19. *
  20. * @var string
  21. */
  22. protected $keyType = 'string';
  23.  
  24. /**
  25. * The "booting" method of the model.
  26. */
  27. protected static function boot()
  28. {
  29. parent::boot();
  30.  
  31. static::creating(function ($model) {
  32. if (empty($model->id)) {
  33. $model->id = (string) Str::uuid();
  34. }
  35. });
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement