Greeenone
8 months ago
166
20
Laravel

One to many - First results and foreach for subobjects

Posted 8 months ago by Greeenone

Hello !

I'm learning laravel since 2 weeks and I have some issues with my HasMany relation.

I have one folder and multiple files. Files belongs to one folder and on folder has many files.

I want to display all files inside in folder.

I get the ID from url and I "send" it to query

$folder = ManagementFolders::where('reference', $reference)->first();

After that, I want to display all files inside but my foreach doesn't work.

Property [file] does not exist on this collection instance.

Please sign in or create an account to participate in this conversation.