Я хочу получить данные с помощью модели eloquent и вернуть их в следующем ответе json.
user[
transactions[],
clients[
ubications[],
contactos[],
plans[],
]
]
В настоящее время я получаю данные о пользователях, транзакциях и клиентах, но не могу получить данные внутри свойств клиента, например, ubications[],contactos[] и plan[].Поэтому мне нужна помощь относительно вложенных свойств, поскольку я уже реализовал взаимосвязь.
Вот модели, которые я использую
User.php
class User extends Authenticatable
{
use Notifiable,HasApiTokens;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function token(){
return $this->access_token;
}
public function transaction(){
return $this->hasMany(Transaction::class);
}
public function plan(){
return $this->hasManyThrough(Plan::class,Client::class);
}
public function ubication(){
return $this->hasManyThrough(Ubicacion::class,Client::class);
}
public function contacto(){
return $this->hasManyThrough(Contacto::class,Client::class);
}
public function client(){
return $this->hasMany(Client::class);
}
}
Client.php
Подробнее здесь: https://stackoverflow.com/questions/587 ... in-laravel