Skip to content
Advertisement

Laravel – Name from foreign key doesn’t show in my blade

I’m making a project where I use the foreign key from a shop in products. The foreign key works but when I want to show it in my blade by using $product->shop_id->shop_name, it gives a blank spot. My foreign key is named ‘shop_id’.Product page without shop name

This is my code:

ProductController:

JavaScript

product.blade.php

JavaScript

Product Model

JavaScript

Shop model

JavaScript

Advertisement

Answer

Your provided wrong namespace and keys in your relationship declaration. You must change as in example below to be able use these methods

Product.php

JavaScript

After that you can access product shop using

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement