0
votes

When trying to insert a user to DB I get

ArgumentCountError Too few arguments to function Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in C:\Repos\Laravel\voleran\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php on line 713 and exactly 2 expected

What should I do?

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
use HasFactory, Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $table = "users";
protected $guarded = [];
const UPDATED_AT = '';
const DELETED_AT = '';
/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
 }


public function registerUser() {
    $user = User::create([
        'username' => request('register_username'),
        'email' => request('register_email'),
        'password' => Hash::make(request('register_password')),
        'token' => Str::random(60),
        'user_code' => Str::random(10),
        'user_news' => request('register_newsletter')
    ]);

    Auth::login($user);

    return redirect()->route('anasayfa');
}

    <form class="form" action="uyelik/kayit" method="POST">
                @csrf
                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- FORM INPUT -->
                    <div class="form-input">
                        <label for="register-email">E-Posta</label>
                        <input type="text" id="register-email" name="register_email">
                    </div>
                    <!-- /FORM INPUT -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->

                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- FORM INPUT -->
                    <div class="form-input">
                        <label for="register-username">Kullanıcı Adı</label>
                        <input type="text" id="register-username" name="register_username" autocomplete="off">
                        <input type="hidden" class="register_username_check" name="register_username_check" value="0">
                    </div>
                    <!-- /FORM INPUT -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->

                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- FORM INPUT -->
                    <div class="form-input">
                        <label for="register-password">Şifre</label>
                        <input type="password" id="register-password" name="register_password">
                    </div>
                    <!-- /FORM INPUT -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->

                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- FORM INPUT -->
                    <div class="form-input">
                        <label for="register-password-repeat">Şifre Tekrar</label>
                        <input type="password" id="register-password-repeat" name="register_password_repeat">
                    </div>
                    <!-- /FORM INPUT -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->

                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- CHECKBOX WRAP -->
                    <div class="checkbox-wrap">
                        <input type="checkbox" id="register-newsletter" name="register_newsletter" checked>
                        <!-- CHECKBOX BOX -->
                        <div class="checkbox-box">
                        <!-- ICON CROSS -->
                        <svg class="icon-cross">
                            <use xlink:href="#svg-cross"></use>
                        </svg>
                        <!-- /ICON CROSS -->
                        </div>
                        <!-- /CHECKBOX BOX -->
                        <label for="register-newsletter">Haberleri ve güncelleştirmeleri e-posta olarak gönder.</label>
                    </div>
                    <!-- /CHECKBOX WRAP -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->

                <!-- FORM ROW -->
                <div class="form-row">
                    <!-- FORM ITEM -->
                    <div class="form-item">
                    <!-- BUTTON -->
                    <button type="submit" name="btnKayitOl" class="button medium primary btnRegister" disabled>Kayıt Ol!</button>
                    <!-- /BUTTON -->
                    </div>
                    <!-- /FORM ITEM -->
                </div>
                <!-- /FORM ROW -->
                </form>
1

1 Answers

0
votes

You shouldn't use

const UPDATED_AT = '';
const DELETED_AT = '';

If you do not wish to have these columns automatically managed by Eloquent, set the $timestamps property on your model to false. Add the following code in your User model

public $timestamps = false;