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
793 stars 48 forks source link

Treat `->with()` chains on Turbo Native redirects differently #119

Closed tonysm closed 10 months ago

tonysm commented 11 months ago

Whenever we're using the InteractsWithTurboNativeRedirects trait and we're using the redirect methods it provides, I think we'd better tweak the ->with() method chains so we could treat it like:

return $this->refreshOrRedirectTo(route('posts.index'))->with(['status' => __('Post created')]);

If the request was from a Turbo Native client, we'd redirect to the refresh route, passing the status as a query string, like /refresh_historical_location?status=Post%dcreated

This way we can read it in the mobile client whenever we're handling these special routes, so no need to flash it in the session.

If the request wasn't from a Turbo Native client, we'd flash the with calls as normal.