简体   繁体   中英

The new record is not added correctly when registering with Laravel

I have been learning Laravel for a few days and encountered a problem. I have these migrations:

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

My 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,
        ]);

I have company in table 'companies' with id = 1.

Registration proceeds correctly, but not all fields are added to the database.

When I register a new user I have empty column IDs: country_id1 and provincial_id1.

Check your $fillable variable in User class. company_id1 and provincial_id1 must be defined in the fillable variable.

$fillable = [
    'name',
    'surname',
    'email',
    'url_address',
    'country_id1',
    'provincial_id1'
    etc...
];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM