【发布时间】:2017-08-02 13:59:50
【问题描述】:
我正在制作一个房地产销售网站。财产可以是房子、公寓、商店等......
我有这样的关系:
模型://属性
class Imovel extends Model...
public function moradia(){
return $this->hasOne(Moradia::class);
}
public function apartamento(){
return $this->hasOne(Apartamento::class);
}
//公寓
public function imovel(){
return $this->belongsTo(Imovel::class);
}
//房子
public function imovel(){
return $this->belongsTo(Imovel::class);
}
迁移:
//属性
Schema::create('imoveis', function (Blueprint $table) {
$table->increments('id');
$table->integer('tipoImovel_id');
$table->string('finalidade',20);
$table->string('titulo',100);
$table->date('data')->nullable();
$table->integer('concelho_id');
$table->string('freguesia',50);
$table->string('rua',150);
$table->decimal('long', 10, 7)->nullable();
$table->decimal('lat', 10, 7)->nullable();
$table->boolean('destaque');
$table->boolean('estado')->default(true);
$table->string('descricao',500);
$table->string('preco',40);
$table->integer('empresa_id')->default(1);
$table->timestamps();
//房子
Schema::create('moradias', function (Blueprint $table) {
$table->integer('imovel_id');
$table->integer('nrPisosConstrucao');
$table->integer('nrWcs');
$table->integer('areaConstrucao');
$table->integer('areaTerreno');
$table->smallInteger('anoConstrucao');
$table->timestamps();
//公寓
Schema::create('apartamentos', function (Blueprint $table) {
$table->integer('imovel_id');
$table->integer('nrQuartos');
$table->integer('nrWcs');
$table->integer('nrPisosEdifio');
$table->integer('areasAcessorias');
$table->integer('areasHabitacionais');
$table->smallInteger('anoConstrucao');
$table->timestamps();
我的问题是:我如何确定该物业是房屋、公寓还是商店......?
我有所有属性的列表,要怎么编辑?我怎么知道它是什么类型的财产?
谢谢
【问题讨论】:
标签: php mysql laravel join eloquent