【发布时间】:2020-10-15 08:35:21
【问题描述】:
很好,我有一个原始属性,我正在创建一个属性,并且该属性具有用户通过复选框选择的特征,我想知道如何将在我的特征表中选择的复选框集与属性一起保存身份证
控制器
$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');
});
}
迁移特征
public function up()
{
Schema::create('characteristics', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('property_id');
$table->string('characteristic');
$table->timestamps();
});
}
看一眼
<div class="form-group">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="ascensor" value="ascensor" name="characteristic[]">
<label class="form-check-label" for="ascensor">Ascensor</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="piscina" value="piscina" name="characteristic[]">
<label class="form-check-label" for="piscina">Piscina</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="turco" value="turco" name="characteristic[]">
<label class="form-check-label" for="turco">Turco </label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="jacuzzy" value="jacuzzy" name="characteristic[]">
<label class="form-check-label" for="ascensor">jacuzzy</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="patio" value="patio" name="characteristic[]">
<label class="form-check-label" for="piscina">Patio/Zona Verde</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="ucerrada" value="ucerrada" name="characteristic[]">
<label class="form-check-label" for="turco">Unidad Cerrada </label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="s_basura" value="s_basura" name="characteristic[]">
<label class="form-check-label" for="ascensor">Shut de basura</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="j_infantiles" value="j_infantiles" name="characteristic[]">
<label class="form-check-label" for="piscina">Juegos Infantiles</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="r_transporte" value="r_transporte" name="characteristic[]">
<label class="form-check-label" for="turco">Rutas de transporte </label>
</div>
</div>
【问题讨论】: