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

[5.6] Another blade helper @dd() #22293

Merged
merged 2 commits into from
Dec 3, 2017
Merged

[5.6] Another blade helper @dd() #22293

merged 2 commits into from
Dec 3, 2017

Conversation

laurencei
Copy link
Contributor

Following on from @csrf and @method blade helpers - the other one I find myself wanting is @dd.

If you've ever had to debug a silly view issue, you might have done {{ dd($var) }} in the past to track it down.

Now you can just do @dd($var) which is much quicker and easier IMO. Can also do @dd($var1, $var2) etc.

@laurencei laurencei changed the title [5.6] Anoter blade helper [5.6] Another blade helper @dd() Dec 3, 2017
*/
protected function compileDd($args)
{
return "<?php dd{$args}; ?>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not be it good if we make it like <?php call_user_func_array('dd', $args); ?>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have dd(...$args) actually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think because of $args is a string, that olso contains parentheses symbols.

Copy link
Contributor Author

@laurencei laurencei Dec 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is literally making a string containing the dd() function - not actually running the function.

$args is a string as passed by blade. So you cant do things like dd(...$args) or call_user_func_array etc - because that turns @dd($var1, $var2) into <?php dd(...($var1, $var)); ?>. This is how blade directives work. 🤷‍♂️

It works perfectly as is (I've tested it against live code). This is just a shortcut for the dd() function and therefore it already runs dd(...$args) under the hood.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, 👍 Then please make changes in the doc block that $args param is an array... It will pass an array and compiler will convert it into <?php dd(...$args); ?>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Modelizer - its not an array. It's a string. That's what Blade passes and generates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then please make it $arg it's making me crazy because $args is always use for an array 😅

@vinterskogen
Copy link
Contributor

The idea is great! ;)

@GrahamCampbell
Copy link
Member

Thanks, but 👎. I don't see the need for this, the original code you posted there looks fine.

@taylorotwell
Copy link
Member

Going to hold off on this for now. :)

@taylorotwell taylorotwell reopened this Dec 3, 2017
@taylorotwell
Copy link
Member

Eh, it's fine I guess but let's not get carried away 😄

@taylorotwell taylorotwell merged commit d1c06b3 into laravel:master Dec 3, 2017
@laurencei laurencei deleted the ddHelper branch December 4, 2017 01:36
@browner12
Copy link
Contributor

it feels like we're getting carried away. I personally am against the @csrf and @method, because the next thing someone is going to ask for is @form and @input and @textarea, and now we're back to the days of our Form builders.

@joshmanders
Copy link
Contributor

I'd have to side with @browner12 here. What's the benefit of using @dd($var1) over {{ dd($var1) }}? the saving of having to type the mustache template tags?

Same with @csrf and @method.

@DxCat
Copy link

DxCat commented Dec 4, 2017

For me, semantically I think @dd() is better than {{ dd() }} since we're not actually inserting/echoing something into the template. The behavior and it's usage is not similar to the usual {{ $var }} or
{!! $var !}}

Although {{ dd($var) }} would work, it would actually compiles down to <?php echo e(dd($var)); ?>
while this @dd() would just compile to <?php dd(123); ?>.

For @csrf and @method though, I don't think they're needed too.

@vinterskogen
Copy link
Contributor

vinterskogen commented Dec 4, 2017

Actually the purpose of helpers like (@dd or @dump) is completely different from examples like @form, @input or @textarea, by the reason they are focused on helping developer to debug an app (and convenient for some situations), and not focused on creating actual interface elements. Creating interface elements, I agree, is responsibility of Form-Builders like 'laravelcollective/html'. Maybe placing them to a saparate satellite-package for blade makes sense.

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.

8 participants