php - Unknown column 'uuid' in 'field list' in laravel

i am trying to create a column "unique" filled with UUID in my "users" table i don't want it to be primary and as i try to register user i am facing this error "Unknown column 'uuid' in 'field list'" i have made a new laravel project and just used "Auth" command on it If You Have Any Other Way To Execute This Please Do Share i just want a unique 5 to 8 character code for my user
Here's My Users Migration:-
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->uuid('unique');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
Here's My User Model:-
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Webpatser\Uuid\Uuid;
use App\Models\Concerns\UsesUuid;
use Illuminate\Support\Str;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = []; // YOLO
public $incrementing = false;
protected $keyType = 'string';
protected static function boot()
{
parent::boot();
self::creating(function ($user) {
$user->uuid = (string) Uuid::generate(4);
});
}
protected $fillable = [
'name', 'email', 'password', 'uuid',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
this is my first time using UUID so i did as per the tutorials as i am a beginner at laravel as well as programming i don't know whats casing the problem Please Help
-ThankYou
Answer
Solution:
Your migration script creates a columnunique
notuuid
, that's the reason you are gettingcolumn uuid not not found
. (please look at to your phpmyadmin screenshot second column)
change this$table->uuid('unique');
to$table->uuid('uuid')->unique();
that may create you a column for uuid.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: failed to create image decoder with message 'unimplemented'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.