3

While there is nothing wrong with the following code it's bothering me because I know it could be a simple one line.

if (Auth::user()->id != 1){
    echo User::where('owner', Auth::user()->id)->where('status', 2)->count();
}else {
    echo User::where('status', 2)->count();
}

I am just having problems constructing the statement. If someone could advise please I have tried several variations of:

echo User::(Auth::user()->id != 1 ? where('owner', Auth::user()->id)->)where('status', 2)->count();
1
  • This is useful. I was working on something using this too. :) Commented May 19, 2018 at 14:17

1 Answer 1

3

Not sure I like ternary for echo (personally), but if you really want to:

echo Auth::user()->id != 1
    ? User::where('owner', Auth::user()->id)->where('status', 2)->count()
    : User::where('status', 2)->count();
Sign up to request clarification or add additional context in comments.

2 Comments

it was more for the fact i knew there was another way, not so certain that it was a better way but one of those things i had to see through! Thank you for your answer.
Hey each to their own, totally :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.