Общая ошибка: 1364 Поле «местоположение» не имеет значения по умолчанию.

я создаю систему входа в систему, используя laravel и sentinel, я добавил новое поле под названием «местоположение» в таблицу пользователей, подобную этой

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');
});

после этого я запускаю код для миграции:обновления и добавляю новое поле в список $fillable, подобный этому

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

и это также мой код в контроллере

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);
    }
}

когда я вставил данные нового пользователя, у меня была эта ошибка

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 ([email protected], ahmed, masry, $2y$10$jAIN6mEXvayLXmY8JmnUHOAu36l3owetg3TuOHnpUtjs1uR89dEYm, 2017-06-02 00:49:53, 2017-06-02 00:49:53))

я попытался решить эту проблему, изменив strict на false, но ошибка сообщения все еще работает, и строка вставляется без значения поля местоположения. Я видел поле местоположения в заполняемом массиве, но я не видел его в массиве атрибутов. может ли кто-нибудь мне помочь?

вот моя форма

<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="[email protected]">
     </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>

person Ahmed Masry    schedule 02.06.2017    source источник
comment
выложи пожалуйста еще форму   -  person Chris Burton    schedule 02.06.2017
comment
да, я выполнил миграцию: обновить после добавления нового поля в $fillable   -  person Ahmed Masry    schedule 02.06.2017


Ответы (1)


В вашей форме у вас есть

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

Обратите внимание на опечатку name="lacation"

Должно быть name="location"

<input type="text" name="location" class="form-control" placeholder="Location">
person Chris Burton    schedule 02.06.2017
comment
@AhmedMasry Если это сработало, примите это как ответ - person Chris Burton; 02.06.2017
comment
У меня такая же проблема. Я проверил все свои орфограммы. Пробовал все возможное, но все равно получал ту же ошибку. Не могли бы вы мне помочь? - person Rashed Hasan; 21.09.2017
comment
@Md.RashedulHasan Пожалуйста, создайте новый вопрос, и я постараюсь вам помочь. - person Chris Burton; 23.09.2017