Я немного знаком с отношениями в Laravel.
Когда я делаю dd
объекта, я получаю это:
Collection {#485 ▼
#items: array:1 [▼
0 => Menu {#484 ▼
#table: "menus"
#fillable: array:6 []
#hidden: array:2 [▶]
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:9 []
#original: array:11 []
#relations: array:2 [▼
"pivot" => Pivot {#486 ▶}
"subMenus" => Collection {#items: array:3 [▼
0 => SubMenu {#488 ▼
#table: "sub_menus"
#fillable: array:5 []
#hidden: array:2 []
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:8 []
#original: array:10 [▼
"id" => 16
"name" => "My name" <--------- this is what I need to get
"created_at" => "2018-11-20 15:19:14"
"updated_at" => "2018-11-20 20:29:34"
Как я могу получить name
значение из модели SubMenu
, которая имеет отношение с моим дд (модель)?
В Menu
Я получил это отношение:
public function subMenus()
{
return $this->belongsToMany('App\SubMenu', 'menu_submenu', 'menu_id', 'submenu_id')->where('estado', Define::ESTADO_ACTIVO)->orderBy('orden');
}
Я пробовал что-то вроде:
dd($MyMenuObject->subMenus());
но не работает.Пробовал с get (), -> подменю и т. Д.
РЕДАКТИРОВАТЬ: Это мои данные:
с dd($perfil_activo->menus);
Я получаю:
