I can’t access properties of my entity, I always get a response saying that the property in question does not exist in my Collection.
With this:
`$teste = $this->user->with('sala')
->where('id', $idUserLogado)
->first();
dd($teste->sala);`
get return normally collection:
`IlluminateDatabaseEloquentCollection {#1405 ▼ // appHttpControllersDashboardController.php:34
#items: array:1 [▼
0 =>
AppModels
Sala {#1412 ▼
#connection: "mysql"
#table: "salas"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:4 [▼
"id" => 4
"numero_sala" => "10A"
"bloco_sala" => "A"
"user_id" => 2
]
#original: array:4 [▶]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: false
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:2 [▶]
#guarded: array:1 [▶]
}
]
#escapeWhenCastingToString: false
}`
but when I try to access a property…
dd($teste->sala->numero_sala);
BOOM:
Property [numero_sala] does not exist on this collection instance.
WHAT?
please.
My methods are right, I don’t think I know how to deal with the Collection, I’m reading the documentation but I can’t find it.