Using the self-relationship with you the following result.:
Collection {#335 ▼
#items: array:7 [▼
0 => Post {#266 ▶}
1 => Post {#267 ▼
#fillable: array:3 [▶]
+incrementing: false
#connection: "sqlite"
#table: "Postes"
#primaryKey: "id"
#keyType: "int"
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▼
"id" => "3b3e6de0-0f04-11e9-bd99-edd41c296507"
"user_id" => "1bb709b0-0f04-11e9-9215-6bc1f33b83a0"
"text" => "Teste de Post2"
"created_by" => "1bb709b0-0f04-11e9-9215-6bc1f33b83a0"
"Post_id" => "24c94740-0f04-11e9-9e4f-cd1208603e5f"
"created_at" => "2019-01-03 03:04:05"
"updated_at" => "2019-01-03 03:04:05"
]
#original: array:7 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼
"todosOsPosts" => Collection {#257 ▼
#items: []
}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
2 => Post {#268 ▼
#fillable: array:3 [▶]
+incrementing: false
#connection: "sqlite"
#table: "Postes"
#primaryKey: "id"
#keyType: "int"
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▼
"id" => "c5eea420-0f05-11e9-81bf-d3f927c4052c"
"user_id" => "1bb709b0-0f04-11e9-9215-6bc1f33b83a0"
"text" => "Teste de Post 22"
"created_by" => "1bb709b0-0f04-11e9-9215-6bc1f33b83a0"
"Post_id" => "24c94740-0f04-11e9-9e4f-cd1208603e5f"
"created_at" => "2019-01-03 03:15:08"
"updated_at" => "2019-01-03 03:15:08"
]
#original: array:7 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼
"todosOsPosts" => Collection {#265 ▼
#items: array:1 [▼
0 => Post {#296 ▼
#fillable: array:3 [▶]
+incrementing: false
#connection: "sqlite"
#table: "Postes"
#primaryKey: "id"
#keyType: "int"
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▶]
#original: array:7 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:2 [▼
"todosOsPosts" => Collection {#297 ▼
#items: array:3 [▼
0 => Post {#311 ▼
#fillable: array:3 [▶]
+incrementing: false
#connection: "sqlite"
#table: "Postes"
#primaryKey: "id"
#keyType: "int"
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▶]
#original: array:7 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
1 => Post {#312 ▶}
2 => Post {#313 ▶}
]
}
"user" => User {#351 ▶}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
]
}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▼
0 => "*"
]
}
3 => Post {#269 ▶}
4 => Post {#270 ▶}
5 => Post {#271 ▶}
6 => Post {#272 ▶}
]
}
I tried to show all the relationships in the view:
<div class="container">
@forelse ($posts as $post)
<div class="bs-callout bs-callout-danger" id="callout-glyphicons-dont-mix">
{{$post->text}}
@forelse ($post->todosOsposts as $bt)
<div class="bs-callout bs-callout-danger" id="callout-glyphicons-dont-mix">
{{$bt->text}}
</div>
@empty
<p>Não possui</p>
@endforelse
@empty
<p>Nenhum post Cadastrado</p>
@endforelse
</div>
At home up I get to the first level of relationship.
If I want to get one more I will have to do
@forelse ($bt->todosOsposts as $bt2)
<div class="bs-callout bs-callout-danger" id="callout-glyphicons-dont-mix">
{{$bt2->text}}
</div>
@empty
<p>Não possui</p>
@endforelse
Is there any way I can show all relationships? to something that helps in this house already implanted within the laravel ..
Thankful