Новая запись не добавляется правильно при регистрации в Laravel - PullRequest
0 голосов
/ 15 мая 2019

Я изучал Laravel в течение нескольких дней и столкнулся с проблемой. У меня есть эти миграции:

Schema::create('companies', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->boolean('enable')->default(0);
            $table->string('name', 85)->nullable();
            $table->string('nip', 12)->nullable();
            $table->mediumText('content')->nullable();
            $table->string('street', 150)->nullable();
            $table->string('number', 8)->nullable();
            $table->string('postal_code', 12)->nullable();
            $table->string('city', 100)->nullable();
            $table->bigInteger('country_id')->default(0);
            $table->bigInteger('provincial_id')->default(0);
            $table->string('contact_person', 85)->nullable();
            $table->string('email', 120)->nullable();
            $table->string('www', 120)->nullable();
            $table->string('phone', 25)->nullable();
            $table->string('regon', 20)->nullable();
            $table->string('key_to_program', 50)->nullable();
            $table->decimal('lng', 10, 8)->default(0);
            $table->decimal('lat', 10, 8)->default(0);
            $table->boolean('enable_map')->default(0);
            $table->string('street2', 150)->nullable();
            $table->string('number2', 8)->nullable();
            $table->string('postal_code2', 12)->nullable();
            $table->string('city2', 100)->nullable();
            $table->bigInteger('country_id2')->default(0);
            $table->bigInteger('provincial_id2')->default(0);
            $table->string('number_vehicle_dismantling_station', 25)->nullable();
            $table->string('city3', 100)->nullable();
            $table->string('decided_to_lead_the_decision', 100)->nullable();
            $table->string('recruitment_contract_number_and_date', 450)->nullable();
            $table->string('agreement_with', 150)->nullable();
            $table->string('opening_hours_monday_friday', 15)->nullable();
            $table->string('opening_hours_saturday', 15)->nullable();
            $table->string('opening_hours_sunday', 15)->nullable();
            $table->date('payment_date')->nullable();
            $table->date('promo_date')->nullable();
            $table->string('url_address', 160);
            $table->timestamps();
            $table->engine = "InnoDB";
        });

Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('company_id')->unsigned();
            $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
            $table->boolean('enable')->default(0);
            $table->string('name', 120)->nullable();
            $table->string('surname', 120)->nullable();
            $table->string('email', 120)->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->bigInteger('counter')->default(0);
            $table->string('url_address', 160);
            $table->string('ip', 25)->nullable();
            $table->boolean('isCompany')->default(0);
            $table->boolean('isMailing')->default(0);
            $table->text('content')->nullable();
            $table->string('nip1', 12)->nullable();
            $table->string('business1', 120)->nullable();
            $table->string('phone1', 60)->nullable();
            $table->string('street1', 150)->nullable();
            $table->string('number1', 8)->nullable();
            $table->string('postal_code1', 12)->nullable();
            $table->string('city1', 100)->nullable();
            $table->bigInteger('country_id1')->default(0);
            $table->bigInteger('provincial_id1')->default(0);
            $table->string('nip2', 12)->nullable();
            $table->string('business2', 120)->nullable();
            $table->string('phone2', 60)->nullable();
            $table->string('street2', 150)->nullable();
            $table->string('number2', 8)->nullable();
            $table->string('postal_code2', 12)->nullable();
            $table->string('city2', 100)->nullable();
            $table->bigInteger('country_id2')->default(0);
            $table->bigInteger('provincial_id2')->default(0);
            $table->string('nip3', 12)->nullable();
            $table->string('business3', 120)->nullable();
            $table->string('phone3', 60)->nullable();
            $table->string('street3', 150)->nullable();
            $table->string('number3', 8)->nullable();
            $table->string('postal_code3', 12)->nullable();
            $table->string('city3', 100)->nullable();
            $table->bigInteger('country_id3')->default(0);
            $table->bigInteger('provincial_id3')->default(0);
            $table->decimal('cash', 9, 2)->default(0);
            $table->decimal('lng', 10, 8)->default(0);
            $table->decimal('lat', 10, 8)->default(0);
            $table->boolean('enable_map')->default(0);
            $table->rememberToken();
            $table->timestamps();
            $table->engine = "InnoDB";
        });

Мой RegisterController.php

protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'surname' => $data['surname'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),

            'url_address' => Str::slug($data['name'], '-'),
            'ip' => RequestFacade::ip(),
            'company_id' => 1,
            'country_id1' => 1,
            'provincial_id1' => 1,
        ]);

У меня есть компания в таблице 'companies' с id = 1.

Регистрация проходит правильно, но не все поля добавлены в базу данных.

Когда я регистрирую нового пользователя, у меня появляются пустые идентификаторы столбцов: country_id1 и provincial_id1.

1 Ответ

1 голос
/ 15 мая 2019

Проверьте переменную $ fillable в классе User.company_id1 и provincial_id1 должны быть определены в переменной с возможностью заполнения.

$fillable = [
    'name',
    'surname',
    'email',
    'url_address',
    'country_id1',
    'provincial_id1'
    etc...
];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...