Sunday, March 12, 2017

Laravel- Search for an ID in multiple tables

I'm making a property sales site. A property can be a house, an apartment, a shop, etc....

I have this relations:

Models: //Properties

class Imovel extends Model...

public function moradia(){
    return $this->hasOne(Moradia::class);
}

public function apartamento(){
    return $this->hasOne(Apartamento::class);
}

//Apartment

 public function imovel(){
    return $this->belongsTo(Imovel::class);
}

//House

 public function imovel(){
   return $this->belongsTo(Imovel::class);
}

Migrations:

//Property

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();

//house

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();

//apartment

  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();

My question is: How will I find out if the property is a house, or apartment, or a shop ...?

I have the list of all the properties, to edit how do I? How do I know what kind of property it is?

Thanks



via D. Lopes

Advertisement