Altafk Altafk - 3 months ago 33
MySQL Question

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'EMAIL' cannot be null

I am new to laravel please give the solution
This is user controller code when i submit the form i am getting email is null but i am inserting email.

there is no laravel issue i think its mysql issue

<?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)
{
}

}


This is migrate table.

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('email');
$table->string('first_name');
$table->string('password');
$table->rememberToken();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}


This is my html file

<div class="row">
<div class="col-md-6">
<h3>Sign Up</h3>
<form action="{{ route('signup') }}" method="post">
<div class="form-group">
<lable for="email">Your Email</lable>
<input class="form-control" type="email" name "email" id="email">
</div>
<div class="form-group">
<lable for="first_name">Your first name</lable>
<input class="form-control" type="text" name="first_name" id="first_name">
</div><div class="form-group">
<lable for="password">Your Password</lable>
<input class="form-control" type="password" name "password" id="password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>


AND THIS I S ROUTE

Route::get('/', function () {
return view('welcome');
});

Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);

Answer

Your HTML is wrong. Replace:

<input class="form-control" type="text" name "email" id="email">
<input class="form-control" type="password" name "email" id="password">

With

<input class="form-control" type="email" name="email" id="email">
<input class="form-control" type="password" name="password" id="password">

After that replace your Controller like this:

$email= $request->input( 'email' );
Comments