Я выполняю отношения в красноречивых, и я не получаю Json, который я хочу. Я использую что-то вроде этого:
return User::with('permissao.telaSistema')->find(26);
производит следующий json:
{
"id" : 1000,
"total_operadores": null,
"permissao": [
{
"tela_sistema": [
{
"id": 7,
"nome_tela": "generic mkt"
}
]
},
{
"tela_sistema": [
{
"id": 6,
"nome_tela": "generic mkt2"
}
]
}
]
}
Не было бы разумнее сгенерировать что-то вроде этого:
{
"id": 1000,
"total_operadores": null,
"permissao": [
{
"tela_sistema": [
{
"id": 7,
"nome_tela": "generic mkt"
},
{
"id": 6,
"nome_tela": "generic mkt 2"
}
]
}
]
}
Интересно, не ошиблись ли мои декларации отношений на модели? Вот мои модели.
class User {
public function permissao(){
return $this->hasMany('App\Permissao', 'operador_id', 'id');
}
}
Permissao класс
Class Permissao
{
public function user() {
return $this->belongsToOne('App\User', 'id', 'operador_id');
}
public function telaSistema() {
return $this->hasOne('App\TelaSistema', 'id', 'tela_id');
}
}
Telas sistema class
TelaSistema class
{
public function permissao()
{
return $this->belongsToMany('App\Permissao', 'id', 'tela_id');
}
}
Вот структура таблиц.
User Permissao Tela_sistema
id (one) -> (many) operador_id
tela_id (many) -> (one) id