Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created July 23, 2021 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cursosdesarrolloweb/fdee97d0788f4f626f9ec298a4a5fd4f to your computer and use it in GitHub Desktop.
Save cursosdesarrolloweb/fdee97d0788f4f626f9ec298a4a5fd4f to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Order extends Model
{
use HasFactory;
protected $fillable = ["token"];
protected static function boot()
{
parent::boot();
self::creating(function(Order $order) {
do {
$token = Str::uuid();
} while (Order::where("token", $token)->first() instanceof Order);
$order->token = $token;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment