【问题标题】:Laravel: Query ExceptionLaravel:查询异常
【发布时间】:2018-04-07 08:59:59
【问题描述】:

数组到字符串的转换(SQL:插入RegisterStudentLRN, dateOfBirth, sex, updated_at, created_at) 值 (1234, 1996-02-10, 女, 2017-10-26 05:30:32, 2017-10-26 05:30:32))

StudentController 存储内容

public function store(Request $request){

     //validation
    $this->validate($request, [
        'LRN' => 'required|max:100',
    ]);

    $student = New Student;
    $student->LRN = $request->input('LRN');
    $student->dateOfBirth = $request->input('dateOfBirth');
    $student->sex = $request->input('sex');

    $student->save();

    return redirect()->back();
}

【问题讨论】:

  • 您将LRNsex 作为数组发送。显示您的 html 代码
  • Lois Arce,看看 madalinivascu 的回答。它会解决问题。

标签: php sql database laravel-5.3


【解决方案1】:

更改以下内容:

$student->sex = $request->input('sex')[0];

输入似乎是一个数组,因此您需要 [0] 处的值 或删除输入名称中的 [] 以在 php 中使用 $request->input('sex')

【讨论】:

  • 你怎么能确定它的sex 而不是任何其他字段?
  • @HimanshuUpadhyay 如果你看截图,在白名单中你可以看到第二项array('Female')
猜你喜欢
  • 2016-10-20
  • 1970-01-01
  • 2019-10-05
  • 2021-04-23
  • 2016-09-24
  • 1970-01-01
  • 2019-09-06
  • 2011-04-21
  • 2018-07-12
相关资源
最近更新 更多