Php SQLSTATE[23000]:完整性约束冲突:1048列';电子邮件';不能为空

Php SQLSTATE[23000]:完整性约束冲突:1048列';电子邮件';不能为空,php,mysql,laravel,Php,Mysql,Laravel,我是拉威尔的新手,请给出解决方案 这是当我提交表单时的用户控制器代码,我收到的电子邮件为空,但我正在插入电子邮件 没有laravel的问题,我认为是mysql的问题 <?php namespace App\http\Controllers; use App\User; use Illuminate\Http\Request; class UserController extends Controller { public function postSignUp(

我是拉威尔的新手,请给出解决方案 这是当我提交表单时的用户控制器代码,我收到的电子邮件为空,但我正在插入电子邮件

没有laravel的问题,我认为是mysql的问题

<?php
namespace App\http\Controllers;

  use App\User;
  use Illuminate\Http\Request;

     class UserController extends Controller
{
   public function postSignUp(Request $request)
   {
     $email = $request['email'];
     $first_name = $request['first_name'];
     $password = bcrypt($request['password']);

     $user = new User();
     $user->email = $email;
     $user->first_name = $first_name;
     $user->password = $password;

     $user-> save();

     return redirect()-> back();
   }

     public function postSignIn(Request $request)
   {
   }

   }
你的HTML是错误的。 替换:


要获取电子邮件值,您应首先添加
=
btw名称和“电子邮件”,然后在控制器内部将
$email=$request['email']
替换为
$email=$request->input('email')

您好,问题在于您正在使用

$email = $request['email'];
如果默认值如下所示为空,则必须传递默认值,或者使mysql字段接受空值

$name = Input::get('email', 'default@gmail.com');

你试过dd($email)?你得到了什么?这可能是由于HTML表单名称错误,无法为电子邮件字段指定名称…请使用
dd($request->all())的结果更新你的帖子插入到
PostSignUp()
的开头。另外,请从view.div class=“row”>中显示适当的路线和表单HTML,注册您的电子邮件您的名字数组:2[▼ “first_name”=>“123456”“\u token”=>“lbnpyvbvyropnvwnglzfctthddwppwwjbeovmyc7”]同一问题我将类型更改为email请您替换我在回答中给出的两行您的HTML格式在
名称“email”
中似乎不正确,因此电子邮件字段未传递给控制器。它应该是
name=“email”
用于电子邮件,而
name=“password”
用于密码字段……实际上,电子邮件数组是空的,这是一个愚蠢的错误。谢谢你,西莉亚,我们刚刚合作过=
Route::get('/', function () {
return view('welcome');
});

 Route::post('/signup', [
       'uses' => 'UserController@postSignUp',
       'as' => 'signup'
]);
<input class="form-control" type="text" name "email" id="email">
<input class="form-control" type="password" name "email" id="password">
<input class="form-control" type="email" name="email" id="email">
<input class="form-control" type="password" name="password" id="password">
$email= $request->input( 'email' );
$email = $request['email'];
$name = Input::get('email', 'default@gmail.com');