-
-
Save cursosdesarrolloweb/fdee97d0788f4f626f9ec298a4a5fd4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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