php - Laravel limit with (not globally) -


I have the following query, which I want to execute with supernatural . (['User name']) with the

  $ restaurant = restaurant :: (['user' = & gt; function ($ query) {$ query}; // this $ query-> where the condition ('confirmation');}]) - & gt; Search ($ ID); I want to get a  restaurant  and it is related to  user  (they are related), but  user  usernames  

I $ hidden to the user model I can add to it, but then they will hide for every query (in the array / JSN form). But I only want to narrow it a bit more for this query.

If I add (wrapping it in or without the array), I get the following result:

  {'id': 1, 'user': Null}  

However, if I remove that selection then I will not be able to enter the full user :

  {'id': 1, 'user': {.. json user data}}  

user exists and the username is not empty How can I go about this?

The output can be found here.

Edit: When I change the value of something that does not exist in that database, I see an error, and with that I have decided that the query is correct, but none of me Do not get the output. (I see when using an invalid column 'test').

  Select `test` from` user`, where `user` .` ​​deleted_at` is zero and` users`. (`) And` User` .` ​​User_type '= Restaurant and `condition` = Confirmation in` userable_id`)  

  $ restaurant = restaurant :: with (['user' = & gt; function ($ query) {$ query- & Gt; where position ('confirmation') - & gt; lists ('username');}]))) - & gt; Find ($ ID); It seems that both methods will work but you need to fulfill one condition - you need to include foreign_ column in the lists. /Choose. I do not know what your connection is but for example, suppose you have the  user  table  restaurant_id  column in which you have to use the following code: 

< (['Username', 'restaurant_id']) with the option of (['user' => function ($ query) {$ query- & gt; Gt; where position ('confirmation');}]) -> & gt; Search ($ ID); (['User' => function ($ query) {$ query- & gt; with <= code>

or

  $ restaurant = restaurant :: ; Where position ('confirmation') - & gt; lists ('username', 'restaurant_id');}]) - & gt; Find ($ ID);  

I do not know that it is possible for n: n relationship. You should also consider that it can be a bit dangerous (there may be some problems) so that you should only play with it, if you have strong reason for catching the selected columns.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -