in my system: a lead belongstomany salespeople a manager belongstomany salespeople i am trying to check if a lead has a manager through the salespeople. this is for a policy so i can make sure a manager can see the leads of their salespeople. something like this: is there a collection method that will allow me to do this? i’ve
Tag: relationship
Laravel relationship where clause is returning records outside relationship
I have a problem where i try to get all users from Site which is defined relationship in Site model and on where clause it returns users that belong to other Site Lets say that my $site_id = 2 and my $searchParam = ‘Tom’. It returns Tom that belongs to Site with site_id=1 but it also returns other Tom that
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
Select specific column from morph relation according to type in Laravel
I am trying to write a query that selects columns from a model then selects some columns from a morph relationship table. But I have no idea to select columns, and relation tables have different columns. So some column has no slug, some have. Models How can I select specific columns from morph relation with checking morph type? I am
Check user if is in chat room Laravel
I have models: ChatRoomMembers ChatRoom so I want to check if auth user is in chat room my relationships: ChatRoom: ChatRoomMembers: Answer So I created relationship in User Model: and I am getting only this user chat rooms
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
I have tried to run an existing laravel project. But during composer update I got this error:
Problem 1 Problem 2 Problem 3 Answer The error messages are quite clear. The packages you want to install require PHP 7, but you have PHP 8 installed. Your options are: Downgrade your PHP version Upgrade the package versions you depend on, if there are newer PHP 8 compatible versions
How to use print all comments for respective posts using relationship in Laravel 8
I am trying to print all comments per post using the relationship, Error: Property [comments] does not exist on the Eloquent builder instance. Post Model class WorkTravel extends Model { use …