Skip to content
Advertisement

Tag: relationship

Eloquent Relationships hasMany use loop

I have a database with multiple address records of a user. When I do “pluck()” and “join()” in the foreach path, I get results. But when I type $user->getAddress->address in structures like hasOne, I get the result I want. In short, can I return the loop in hasMany more practically? Following my code: user Table adress Table UserModel Controller Answer

TCGVoyager doesn’t get translation on relationship

I use Voyager admin interface (v.1.4) for Laravel (v8.0). Voyager supports multiple languages (official documentation: https://voyager-docs.devdojo.com/v/1.4-1/core-concepts/multilanguage). I have this relationship: Process belongsToMany WorkMachine Process hasMany Product Process model: WorkMachine model: Product model: In my controller: The problem is: the Process translatable text works, the output language depends from app()->getLocale(). But the workmachine texts and products texts aren’t translated. I try

Query One to Many Relation in Laravel 8

I have one to many relation for User and Student. Model User.php Model Student.php and in Controller.php it will run and return json can I custom select in Students, only show firstname and lastname ? Answer You should use API Resources for this. Here’s a link to the official documentation: https://laravel.com/docs/8.x/eloquent-resources Your student collection could look something like this:

store data into pivot table laravel 8

i have manytomany relation ship between categroy and product category model product model the pivot table what should i do after this i did not undrestant how attach will work in pivot table and return it with the product as json response ? edit this is the schema i am working on i want to give each product it’s own

Advertisement