1

i create a login system using laravel and sentinel i added a new field called 'location' in users table like this

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('email');
    $table->string('password');
    $table->text('permissions')->nullable();
    $table->timestamp('last_login')->nullable();
    $table->string('first_name')->nullable();
    $table->string('last_name')->nullable();
    $table->string('location');   //this is my field
    $table->timestamps();
    $table->engine = 'InnoDB';
    $table->unique('email');
});

after that i run code to migrate:refresh and i added the new field to $fillable list like that

protected $fillable = [
    'email',
    'password',
    'last_name',
    'first_name',
    'permissions',
    'location'
];

and this is my code in controller also

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Sentinel;

class RegistrationController extends Controller
{
    public function register()
    {
        return view('authentication.register');
    }

    public function postRegister(Request $request)
    {
        $user = Sentinel::registerAndActivate($request->all());
        dd($user);
    }
}

when i in inserted new user's data i had this error

QueryException in Connection.php line 770: SQLSTATE[HY000]: General error: 1364 Field 'location' doesn't have a default value (SQL: insert intousers(email,first_name,last_name,password,updated_at,created_at) values (elmasry200400@gmail.com, ahmed, masry, $2y$10$jAIN6mEXvayLXmY8JmnUHOAu36l3owetg3TuOHnpUtjs1uR89dEYm, 2017-06-02 00:49:53, 2017-06-02 00:49:53))

i tried to solve this problem by change strict to false but the message error still work and the row inserted without the location field value i saw the location field in fillable array but i didn't see it in attributes array can any one help me?

here it is my form

<form action="/register" method="POST">
  {{ csrf_field() }}

  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-envelope"></i></span>

        <input type="email" name="email" class="form-control" placeholder="example@example.com">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-user"></i></span>

        <input type="text" name="first_name" class="form-control" placeholder="First Name">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-user"></i></span>

        <input type="text" name="last_name" class="form-control" placeholder="Last Name">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-map-marker"></i></span>

        <input type="text" name="lacation" class="form-control" placeholder="Location">
     </div>                           
  </div>


  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-lock"></i></span>

        <input type="password" name="password" class="form-control" placeholder="Password">
     </div>                           
  </div>

  <div class="form-group">
     <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-lock"></i></span>

        <input type="password" name="password_confirmation" class="form-control" placeholder="Password Confirmation">
     </div>                           
  </div>

   <div class="form-group">

        <input type="submit" value="Register" class="btn btn-success pull-right">

  </div>                      
</form>
Chris Burton
  • 1,195
  • 6
  • 19
  • 54
Ahmed Masry
  • 17
  • 1
  • 6

1 Answers1

1

In your form, you have

<input type="text" name="lacation" class="form-control" placeholder="Location">

Notice the misspelling of name="lacation"

It should be name="location"

<input type="text" name="location" class="form-control" placeholder="Location">
Chris Burton
  • 1,195
  • 6
  • 19
  • 54