php - Filtering Eloquent ORM query by relation -


I need to filter my supernatural query with the relation. I have the following link:

There are several ** achievements in the user **

There are several ** achievements in the game **

Let me now play a game. For those who receive it, the achievements of User A should be filtered. This can be done like this:

$ user-> Achievements () - & gt; While Game ID ($ game-> ID)

It's okay, but can I use a straight $ game object instead of filtering by the ugly id column?

$ game is injected into the closing method and curious loading During my query, there is a better way in my opinion

where and or wherehere are to limit the outcome of the inquiry to the relationship.

  $ game = game :: find (GameID); // Magic is used here $ user = user :: where is ('achievements', function ($ query) usage ($ game) {$ query-> where ('gameId', $ game- & gt; ID);}) - & gt; From ('Achievements') // If you want to keep them in the collection - & gt; get receive ();   

This limits both with user (main archive result) achievement (relationship).

'sa detailed information (inquiry related relationship).

If you want to filter only achievements , but do not want to do user , you only need to have a closure function Required:

  $ game = game :: find ($ gameID); // (wizard) here with $ user = user :: (array ('Achievements' = & gt; function ($ query) usage ($ game) {$ query- & gt; where ('gameId', $ game- & Gt; ID);}))) - & gt; get ();  

This just limits the achievments relationship, but does not affect user (main collection)

'Detailed description (anxious loading constains)


Comments

Popular posts from this blog

Editing Python Class in Shell and SQLAlchemy -

import - Python ImportError: No module named wmi -

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -