right now i do this on my view and i only get to see the sub categories but not the actual main categories:
<div class="flex-col items-center justify-center w-full py-4">
@foreach($categories as $category)
<a href="{{ route('by-category', $category) }}" class="text-black font-bold uppercase">
{{ $category->title }} <i class="fas ml-2"></i>
</a>
@endforeach
</div>
The dump and die function shows me the correct list and the correct structure which is this:
News -> main
- Upcoming Releases -> sub
- New Music
- Lists
Reviews -> main
Video -> main
- Music Videos
- Covers
- Funny Shid
- Live Footage
Illuminate\Database\Eloquent\Collection {#1692 ▼ // app/Http/Controllers/PostController.php:32
#items: array:3 [▶
0 => App\Models\Category {#2000 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 6
"title" => "News"
"slug" => "news"
"created_at" => "2023-06-06 23:42:46"
"updated_at" => "2023-06-06 23:42:46"
"parent_id" => null
]
#original: array:6 [▶
"id" => 6
"title" => "News"
"slug" => "news"
"created_at" => "2023-06-06 23:42:46"
"updated_at" => "2023-06-06 23:42:46"
"parent_id" => null
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶
"subCategory" => Illuminate\Database\Eloquent\Collection {#1974 ▶
#items: array:3 [▶
0 => App\Models\Category {#1577 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 9
"title" => "New Music"
"slug" => "new-music"
"created_at" => "2023-06-06 23:43:17"
"updated_at" => "2023-06-06 23:43:17"
"parent_id" => 6
]
#original: array:6 [▶
"id" => 9
"title" => "New Music"
"slug" => "new-music"
"created_at" => "2023-06-06 23:43:17"
"updated_at" => "2023-06-06 23:43:17"
"parent_id" => 6
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
1 => App\Models\Category {#1989 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 10
"title" => "Lists"
"slug" => "lists"
"created_at" => "2023-06-06 23:43:36"
"updated_at" => "2023-06-06 23:43:36"
"parent_id" => 6
]
#original: array:6 [▶
"id" => 10
"title" => "Lists"
"slug" => "lists"
"created_at" => "2023-06-06 23:43:36"
"updated_at" => "2023-06-06 23:43:36"
"parent_id" => 6
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
2 => App\Models\Category {#1624 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 11
"title" => "Upcoming Releases"
"slug" => "upcoming-releases"
"created_at" => "2023-06-06 23:43:48"
"updated_at" => "2023-06-06 23:43:48"
"parent_id" => 6
]
#original: array:6 [▶
"id" => 11
"title" => "Upcoming Releases"
"slug" => "upcoming-releases"
"created_at" => "2023-06-06 23:43:48"
"updated_at" => "2023-06-06 23:43:48"
"parent_id" => 6
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
]
#escapeWhenCastingToString: false
}
]
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
1 => App\Models\Category {#1682 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 7
"title" => "Video"
"slug" => "video"
"created_at" => "2023-06-06 23:42:51"
"updated_at" => "2023-06-06 23:42:51"
"parent_id" => null
]
#original: array:6 [▶
"id" => 7
"title" => "Video"
"slug" => "video"
"created_at" => "2023-06-06 23:42:51"
"updated_at" => "2023-06-06 23:42:51"
"parent_id" => null
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶
"subCategory" => Illuminate\Database\Eloquent\Collection {#1803 ▶
#items: array:3 [▶
0 => App\Models\Category {#1887 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 12
"title" => "Music Videos"
"slug" => "music-videos"
"created_at" => "2023-06-06 23:44:38"
"updated_at" => "2023-06-06 23:44:38"
"parent_id" => 7
]
#original: array:6 [▶
"id" => 12
"title" => "Music Videos"
"slug" => "music-videos"
"created_at" => "2023-06-06 23:44:38"
"updated_at" => "2023-06-06 23:44:38"
"parent_id" => 7
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
1 => App\Models\Category {#1775 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 13
"title" => "Covers"
"slug" => "covers"
"created_at" => "2023-06-06 23:44:55"
"updated_at" => "2023-06-06 23:44:55"
"parent_id" => 7
]
#original: array:6 [▶
"id" => 13
"title" => "Covers"
"slug" => "covers"
"created_at" => "2023-06-06 23:44:55"
"updated_at" => "2023-06-06 23:44:55"
"parent_id" => 7
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
2 => App\Models\Category {#1897 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 14
"title" => "Live Footage"
"slug" => "live-footage"
"created_at" => "2023-06-06 23:45:02"
"updated_at" => "2023-06-06 23:51:28"
"parent_id" => 7
]
#original: array:6 [▶
"id" => 14
"title" => "Live Footage"
"slug" => "live-footage"
"created_at" => "2023-06-06 23:45:02"
"updated_at" => "2023-06-06 23:51:28"
"parent_id" => 7
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
]
#escapeWhenCastingToString: false
}
]
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
2 => App\Models\Category {#1571 ▶
#connection: "mysql"
#table: "categories"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:6 [▶
"id" => 8
"title" => "Reviews"
"slug" => "reviews"
"created_at" => "2023-06-06 23:43:05"
"updated_at" => "2023-06-06 23:43:05"
"parent_id" => null
]
#original: array:6 [▶
"id" => 8
"title" => "Reviews"
"slug" => "reviews"
"created_at" => "2023-06-06 23:43:05"
"updated_at" => "2023-06-06 23:43:05"
"parent_id" => null
]
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶
"subCategory" => Illuminate\Database\Eloquent\Collection {#1861 ▶
#items: []
#escapeWhenCastingToString: false
}
]
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: []
#visible: []
#fillable: array:3 [▶
0 => "title"
1 => "slug"
2 => "parent_id"
]
#guarded: array:1 [▶
0 => "*"
]
}
]
#escapeWhenCastingToString: false
}