Level 54
@grunburg you are not getting a value for 'handle'. Have you added it to $fillable in your User model?
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm making an API authentication system. Currently testing register action, I ran into this problem, that I can't solve:
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \"handle\" violates not-null constraint\nDETAIL: Failing row contains (12, Test, null, [email protected], null, password, null, 2020-09-02 10:59:53, 2020-09-02 10:59:53). (SQL: insert into \"users\" (\"email\", \"name\", \"password\", \"updated_at\", \"created_at\") values ([email protected], Test, password, 2020-09-02 10:59:53, 2020-09-02 10:59:53) returning \"id\")
Im posting data from Postman with all the keys and values, including handle (@username).
Authcontroller.php
class AuthController extends Controller
{
public function register(Request $request)
{
$data = $request->validate([
'email' => ['email', 'unique:users', 'required'],
'name' => ['string', 'max:225', 'required'],
'handle' => ['string', 'alpha_num', 'unique:users', 'max:16', 'required'],
'password' => ['confirmed', 'required']
]);
$user = User::create($data);
$token = $user->createToken('Auth')->accessToken;
return response(['user' => $user, 'token' => $token], 201);
}
}
migration file:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('handle')->unique();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
Is there some kind of typo I don't see or just something wrong with my code?
@grunburg you are not getting a value for 'handle'. Have you added it to $fillable in your User model?
Please or to participate in this conversation.