Skip to content

Instantly share code, notes, and snippets.

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