1
I have the following tables:
contacts => id - name - state - city
states => id - status - acronym
cities => id - city - id_state
And the following models:
Php state.
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Estado extends Model{
protected $table = 'estados';
public $timestamps = false;
public function contatos(){
return $this->hasMany('App\Contato');
}
}
Contact.php
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Contato extends Model{
protected $table = 'contatos';
public $timestamps = false;
public function estados(){
return $this->hasMany('App\Estado');
}
}
And to list:
$request = Contato::orderBy($column, $sort)->paginate($paginator);
And how do I make, instead of the status id, appear the name of the state(the same goes for the neighborhood)
Thank you for the explanation, but you are making the following mistake:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'estados.contato_id' in 'where clause' (SQL: select * from
stateswhere
states.
contact_idin (1, 5, 9, 13, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21))
. Because it is trying to search 'contact_id' within the table 'states'?– Kelvym Miranda
`$this->hasOne('App Status', 'local_key', 'fk_key); in the model, change by your keys
– juniorb2ss
It worked out! Vlw man. I have a lot to learn from Aravel yet.
– Kelvym Miranda
@Kelvymmiranda then mark the answer as correct.
– juniorb2ss