如何修复“ SQLSTATE [42S22]”:找不到列:1054“ where子句”中的未知列“ id”(SQL:从“ users”中选择*,其中“ id” = 0限制1)

时间:2018-12-31 09:11:12

标签: php laravel

我已经编辑了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']),
            ]);
        }
    }

1 个答案:

答案 0 :(得分:1)

自动假定您的主键列将为id。为了使其正常工作,您应该在模型User.php中设置主键:

protected $primaryKey = 'student_no';