hotwired-laravel / turbo-laravel

This package gives you a set of conventions to make the most out of Hotwire in Laravel.
https://turbo-laravel.com
MIT License
803 stars 50 forks source link

Why does response()->turboStreamView() expect a view instance? #7

Closed georgeboot closed 3 years ago

georgeboot commented 3 years ago

While playing around with this (awesome) package, I noticed the following:

return response()->turboStreamView(view('comments.turbo_created_stream', [
  'comment' => $comment,
]));

What is the reason you expect a view instance as the argument, and not just the view name + data? This feels way more natural to me.

tonysm commented 3 years ago

That's because I don't want to replicate the functionality in Laravel itself. I would agree the naming looks off, so something like turboStreamUsing(view()) might read better?

Personally, I use PHPStorm, and the macros, while they are great, I don't get auto-completion, so I wanted to limit the "unkowns" or conventions using the package. I'll test it out again here to see if the auto-completion thing works with macros.

georgeboot commented 3 years ago

Perhaps the most Laravel way of doing this, is t do a is_string($view). If true, wrap it in a view call with the optional second argument.

tonysm commented 3 years ago

Added an alternative syntax to the turboStreamView helper. Checkout the docs.