第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

傳遞給 Illuminate\Database\Grammar::parameterize()

傳遞給 Illuminate\Database\Grammar::parameterize()

PHP
慕村225694 2023-07-01 13:10:07
很好,我有一個原始屬性,正在創(chuàng)建一個屬性,該屬性具有用戶通過復選框選擇的特征,我想知道如何使用屬性 id 保存在特征表中選擇的復選框集控制器           $characteristics = new Characteristic;                $characteristics->characteristic = $request->input('characteristic');            $characteristics->save();        遷移特性 public function up()    {        Schema::create('properties', function (Blueprint $table) {            $table->increments('id');            $table->string('name')->nullable;            $table->string('price')->nullable;            $table->text('description')->nullable;            $table->unsignedBigInteger('property_type_id')->nullable();            $table->unsignedBigInteger('offer_type_id')->nullable();            $table->unsignedBigInteger('spaces_id')->nullable();            $table->unsignedBigInteger('departaments_id')->nullable();            $table->unsignedBigInteger('municipalities_id')->nullable();            $table->unsignedBigInteger('details_id')->nullable();            $table->unsignedBigInteger('characteristics_id')->nullable();            $table->string('images')->nullable;            $table->float('lat')->nullable;            $table->float('lng')->nullable;            $table->string('address')->nullable;                        $table->timestamps();                        $table->foreign('property_type_id')->references('id')->on('property_type')->onDelete('cascade');            $table->foreign('offer_type_id')->references('id')->on('offer_type')->onDelete('cascade');            $table->foreign('spaces_id')->references('id')->on('spaces')->onDelete('cascade');            $table->foreign('departaments_id')->references('id')->on('departaments')->onDelete('cascade');            $table->foreign('municipalities_id')->references('id')->on('municipalities')->onDelete('cascade');            $table->foreign('details_id')->references('id')->on('details')->onDelete('cascade');            $table->foreign('characteristics_id')->references('id')->on('characteristics')->onDelete('cascade');        });    }
查看完整描述

2 回答

?
慕絲7291255

TA貢獻1859條經(jīng)驗 獲得超6個贊

看起來你的$request->input('characteristic');是一個數(shù)組而不是字符串。


你需要一個循環(huán)來解決這個問題。一種方法可以是:


$data = []


foreach ($request->input('characteristic') as $characteristic) {

   $data[] = [

      'characteristic' => $characteristic,

      'property_id' => '' // something

   ];

}


Characteristic::insert($data);

->saveMany()更好的方法是通過設(shè)置關(guān)系來使用hasMany()。


$characteristics = [];


foreach ($request->input('characteristic') as $characteristic) {

   $characteristics = new Characteristic([

        'characteristic' => $characteristic

   ]);

}


$property->characteristics()->saveMany($characteristics);


查看完整回答
反對 回復 2023-07-01
?
千萬里不及你

TA貢獻1784條經(jīng)驗 獲得超9個贊

我能夠保存數(shù)據(jù)如下


$piso_id = $properti->id;

        

            foreach ($request->input('characteristic') as $characteristic) {

               

               $charc = new Characteristic;

               

               $charc->property_id = $piso_id;

               $charc->characteristic = $characteristic;

               $charc->save();

            }


查看完整回答
反對 回復 2023-07-01
  • 2 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號