#php #laravel
#php #laravel
Вопрос:
При попытке вставить пользователя в DB я получаю
ArgumentCountError Слишком мало аргументов для функции IlluminateDatabaseEloquentModel::setAttribute(), 1 передано в C:ReposLaravelvoleranvendorlaravelframeworksrcIlluminateDatabaseEloquentConcernsHasAttributes.php в строке 713 и ровно 2 ожидаемых
Что мне делать?
<?php
namespace AppModels;
use IlluminateContractsAuthMustVerifyEmail;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
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:
Вы не должны использовать
const UPDATED_AT = '';
const DELETED_AT = '';
Если вы не хотите, чтобы Eloquent автоматически управлял этими столбцами, установите для свойства $timestamps в вашей модели значение false . Добавьте следующий код в свою пользовательскую модель
public $timestamps = false;
Комментарии:
1. Спасибо за ваш комментарий, не забудьте после редактирования ввести ‘composer dump-автозагрузка’ в терминал.