i made one-to-many relation in laravel with category and product, but the problem is that the relation is ok to categroy side but on the product side when i fetch data then they say me "Attempt to read property "name" on null" [this is category model]this is product blade]
this is product controller i am trying to fetch the product with related category name
setting up a basic one-to-many relationship between Category and Product models in Laravel
Imagin you have a Category model with the following product relationship
And a Product model with the following category relationship
Now, in the controller, when fetching products with their related category name, you can use eager loading
In your blade view 'products/index.blade.php' , you can loop through the products and access the related category name
Make sure your database tables are set up with the foreign key constraints correctly. The products table should have a category_id column that references the id column in the categories table