php - Laravel selecting data with multiple where clauses and returning any pivot data -
I have a relationship with my app where an organization can have many users and many users create multiple organizations in my organization This may look like,
organization. Php
Public function users () {return $ this-> Affiliate ToMany ('Users') - & gt; WithPivot ('is_admin'); }
User.php
Public function organizations () {$ this- & gt; Affiliation organization (organization)); }
What do I want to do, a query is run in which there is multiple where the clause and then return the row data and any pivot data.
For one where I will do the following,
$ org = Organization :: Search (1);
$ orgUsers = $ Org- & gt; User ()
;
I do not understand that if I also need a user, how many crowds would I use?
Assume that you want to add wheree ()
to users, Something like this (user is loading anxious)
$ constraints = ['fname' = & gt; 'John', 'Laname' = & gt; 'the deer']; $ Org = (= 'user' = & gt; function ($ query) usage ($ constraint) {foreach ($ $ = $ $ as valued) $ query- & gt; where ($ fields, $ Val); // If you simply admin users your axis table field $ query- & gt; pivot-> where ('is_admin', true);}]) -> & gt; Search ($ id) you want to use; Or, you can get them all, and filter them if you need a collection of users, and a collection of administrators $ Org = Organization:: (with 'those') - & gt; ($ Id) is received; $ Admin = $ org- & gt; User- & gt; Filter (function ($ user) {return $ user-> pivot-> iadmin});
Comments
Post a Comment