Search cross-results in related tables

1

I created several tables:

Users:

chave primária
email
senha

Physical Detail:

user_id
altura

Personal Information:

user_id
estado_civil

Now I'm having trouble fetching cross-results.

Example: Find users with altura = 170 and at the same time estado_civil = casado .

I tried to group the wheres , but it's getting a bit complex, and worse, the results only bring values from the first table.

    
asked by anonymous 01.09.2014 / 05:36

1 answer

2

I create the model but I always call what I need in the model. I'll leave the code with only the part you need

Template According to the Laravel Website

DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.id', 'contacts.phone', 'orders.price')
            ->get();

Controller Any

$variavel = ModelUsuarios::join('tabeladadospessoais', 'ModelUsuarios.id', '=', 'tabeladadospessoais.user_id')->select('tabeladadospessoais.email', 'tabeladadospessoais.nome', 'tabeladadospessoais.endereco')->get();

Then you just have to call the view.

$this->layout->content = View::make('nome.view')->with('registro',$variavel);

NOTE: Do not forget to use "Use" and put the model name (ModelUsers).

    
02.09.2014 / 17:38