When a user registers, each user receives a seven-digit code stored in the database. Each code must be unique and must not be created a second time. How can I ensure that each code stored is unique and that no error messages occur when an existing code is created?
Function
$randomstring = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 7);
Table
Schema::create('invites', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->text('greeting')->nullable();
$table->string('url')->unique();
$table->timestamps();
});
Aucun commentaire:
Enregistrer un commentaire