我在Laravel 5.5中構建GraphQL API,並且從User::create()
得到錯誤,說我做了不提供「密碼」欄的值,即使我確實如此。這是從User::create()
完整的消息:Laravel:'列中的空值'密碼'違反了非空約束',即使密碼是絕對提供的
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \"password\" violates not-null constraint
DETAIL: Failing row contains (507, null, null, 2017-09-23 14:12:11, 2017-09-23 14:12:11, 658495, 56854685, Joe, Appleseed, royal, 1970-01-01, +31684736248, null, Poplar St, 14a, 1012AB, London, null, [email protected], [email protected], null). (SQL: insert into \"users\" (\"wid\", \"unumber\", \"first_name\", \"last_name\", \"civil_status\", \"birthdate\", \"phone_number\", \"street\", \"street_number\", \"postal_code\", \"city\", \"email_address_overwatch\", \"email_address_mindef\", \"updated_at\", \"created_at\") values (658495, 56854685, Joe, Appleseed, royal, 1970-01-01, +31684736248, Poplar St, 14a, 1012AB, London, [email protected], [email protected], 2017-09-23 14:12:11, 2017-09-23 14:12:11) returning \"id\")
這裏是產生它,裏面的代碼我UserRepository
:
/**
* Creates a new User with $data
*
* @param array $data
* @return User
*/
public function create(array $data): User
{
$data['password'] = bcrypt($data['password']);
$user = User::create($data);
$this->log(Auth::user(), $user, 'created');
return $user;
}
我覺得這是令人難以置信的奇怪,因爲我肯定提供一個值密碼。我可以看到,通過使用dd($data)
:(右下$data['password'] = bcrypt($data'password');
array:15 [
\"wid\" => \"658495\"
\"unumber\" => \"56854685\"
\"first_name\" => \"Joe\"
\"last_name\" => \"Appleseed\"
\"civil_status\" => \"royal\"
\"birthdate\" => \"1970-01-01\"
\"phone_number\" => \"+31684736248\"
\"street\" => \"Poplar St\"
\"street_number\" => \"14a\"
\"postal_code\" => \"1012AB\"
\"city\" => \"London\"
\"email\" => \"[email protected]\"
\"email_address_overwatch\" => \"[email protected]\"
\"email_address_mindef\" => \"[email protected]\"
\"password\" => \"$2y$10$FdLbx/dYkdrjhGNcuCWKkO.bg013Gn0mhs7nKN.nyNztlykWx4jDC\"
]
正如你所看到的,肯定是有這個陣列中的password
場,這怎麼可能,我得到這個錯誤
一些環境?信息:
PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 2 2017 05:56:43) (NTS)
psql (PostgreSQL) 9.5.8
Laravel Framework 5.5.2
你不應該使用'Hash :: make($ data ['password'])'? –
@lawrencecherone我不這麼認爲。標準laravel認證腳手架使用bcrypt –