Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created Jul 23, 2021
Embed
What would you like to do?
<?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