Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dd_when Helper to Conditionally Trigger dd() #53300

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

afiqiqmal
Copy link

Propose helper function, dd_when, allowing conditional debugging with dd(). This function provides a simple way to invoke dd() based on a boolean condition.

Example Usage:

dd_when($user->isAdmin(), $user, 'Only admins can see this debug info');

Sample Use case:

Before

foreach($users as $user) {
      if ($user->dontHaveOrder()) {
            dd($user->id);
      }
     ....
}

After

foreach($users as $user) {
      dd_when($user->dontHaveOrder(), $user->id);
     ....
}

@rodrigopedra
Copy link
Contributor

foreach($users as $user) {
      $user->dontHaveOrder() && dd($user->id);
     ....
}

Also, this has been attempted before: #52862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants