0
即時做一個物業銷售網站,我有一個高級搜索,例如臥室數量。Laravel - 如何知道屬性是否存在於相關表
但我有像沒有臥室屬性的商店的屬性,如何知道每個表我必須搜索像公寓或房子。 我使用範圍和位置和類型的屬性工作正常。
我的屬性模型
public function atributos(){
//se for moradia
if ($this->tipoimovel_id == 1) {
return $this->hasOne(Moradia::class);
}
//se for apartamento
else if ($this->tipoimovel_id == 2) {
return $this->hasOne(Apartamento::class);
}
//se for loja
else if ($this->tipoimovel_id == 3) {
return $this->hasOne(Loja::class);
}
//se for armazem
else if ($this->tipoimovel_id == 4) {
return $this->hasOne(Armazem::class);
}
//se for terreno para construção
else if ($this->tipoimovel_id == 5) {
return $this->hasOne(TerrenoConstrucao::class);
}
// se for terreno para outros fins
else if ($this->tipoimovel_id == 6) {
return $this->hasOne(TerrenoOutrosFins::class);
}
}
倉庫不要有臥室
數Schema::create('armazens', function (Blueprint $table) {
$table->integer('imovel_id');
$table->integer('areaAcessoria');
$table->integer('areaTotal');
$table->smallInteger('anoConstrucao');
$table->timestamps();
});
房子有
Schema::create('moradias', function (Blueprint $table) {
$table->integer('imovel_id');
$table->integer('nrPisosConstrucao');
$table->integer('nrQuartos');
$table->integer('nrWcs');
$table->integer('areaConstrucao');
$table->integer('areaTerreno');
$table->smallInteger('anoConstrucao');
$table->timestamps();
});
我的範圍由臥室的數量來搜索
public function scopeProcuraNrQuartos($query,$nrQuartos){
if ($nrQuartos) $query->where($this->atributos()->nrQuartos , '>=' , $nrQuartos);
}
我知道它的錯誤,但是存在一些驗證以知道該屬性是否存在於表中? 謝謝
我不太清楚我理解你的問題,但我認爲你w ant https://laravel.com/api/5.4/Illuminate/Database/Query/Builder.html#method_whereExists – Bebras