Laravel에서 프로젝트를 생성했지만 로그인 및 등록 할 수 없습니다. 등록하려고하면 동일한 페이지에 남아 있고 모든 필드가 동일하게 유지되고 암호 필드는 비어 있습니다. 로그인 페이지에서 "이러한 자격 증명은 우리 기록과 일치합니다. ". 데이터베이스를 삭제하고 새로 생성하고 php artisan migrate 또는 migrate : fresh and refresh 그러나 여전히 작동하지 않습니다. phpmyadmin에서 사용자 또는 관리자를 입력하려고하면이 오류가 표시됩니다." 부서 테이블과 사용자 테이블이 부서 ID와 함께 외부 키와 기본 키가 결합되어 오류가 발생했는지 알 수 없습니다.
Department.php
public function users()
{
return $this->hasMany(User::class);
}
User.php
public function users()
{
return $this->belongsTo(Department::class);
}
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');//create_users_table
//$table->text('avatar');
$table->string('name');
$table->string('lastname');
$table->string('phone');
$table->string('jobtitle');
$table->integer('department_id');
$table->timestamps();
$table->string('usertype')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
});
}
public function up()
{
Schema::create('departments', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->timestamps();
});
}
RegisterController.php
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = RouteServiceProvider::HOME;
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
return Validator::make($data, [
//'avatar' => ['image', 'mimes:jpeg,bmp,png,jpg', 'max:2048'],
'name' => ['required', 'string', 'max:255'],
'lastname' => ['required', 'string', 'max:255'],
'phone' => ['required', 'string', 'max:10', 'min:10'],
'jobtitle' => ['required', 'string', 'max:255'],
'department_id' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'lastname' => $data['lastname'],
'phone' => $data['phone'],
'jobtitle' => $data['jobtitle'],
'department_id' => $data['department'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
1062 - Duplicate entry '[email protected]' for key 'users_email_unique'
이 오류는 두 개의 이메일 주소가 DB에서 동일하고 마이그레이션에서 이메일 필드를 고유 한 것으로 정의했음을 의미합니다. 따라서이 오류가 발생합니다.
양식이 작동하지 않고 오류가 표시되지 않으면 유효성 검사 오류가있을 수 있습니다. 여기에 모두 표시하는 방법이 있습니다.
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다