我已经编辑了Laravel提供的默认注册表格。
我想用'id'
代替'student_no'
。
如何在查询中进行更改?由于该查询是自动生成的,因此无法找到该查询。下面提到的代码是RegisterController.php中的代码。
RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|-----------------------------------------------------------------------
use RegistersUsers;
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'student_no'=> 'required|unique:users',
'name' => 'required|string|max:255',
'CID_No'=> 'required|max:8',
'DOB'=> 'required',
'Department'=> 'required',
'Programme'=> 'required',
'email' => 'required|string|email|max:255|unique:users',
//'Joining_Year'=> 'required',
'graduation_Year'=> 'required',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'student_no'=> $data['student_no'],
'name' => $data['name'],
'CID_No' => $data['CID_No'],
'DOB' => $data['DOB'],
'Department' => $data['Department'],
'Programme' => $data['Programme'],
'email' => $data['email'],
'Joining_Year' => $data['Joining_year'],
'graduation_Year' => $data['graduation_Year'],
'password' => bcrypt($data['password']),
]);
}
}
答案 0 :(得分:1)
自动假定您的主键列将为id
。为了使其正常工作,您应该在模型User.php
中设置主键:
protected $primaryKey = 'student_no';