@Danny971 why are you working so much against Laravel's conventions??? Your approach to fetching the categories and associated product is, frankly, ridiculous. The upshot of your approach is this nonsense:
@foreach(explode(',', $category->products) as $product)
So that you are aware, you are using the Query Builder to fetch the Category and Product data. This means that you will get a Collection of stdClass objects not Category model instances. And, you do not select either the Category or Product id column, hence the error message.
Just do the right thing, and define a relationship between Category and Product models:
// Category
public function products()
{
return $this->hasMany(Product::class);
}
Then the Controller action can look like this:
public function fetchCategoryAndProductData()
{
$categoryAndProducts = Category::with('products')->get();
return view('categories', ['categoryAndProducts' => $categoryAndProducts]);
}
Finally, in the view template:
@foreach($category->products as $product)
<!-- form -->
The rest of your markup is nonsense; sort that out!