You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blade-helpers.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
extends: _layouts.v1-docs
3
-
title: Blade Directives
4
-
description: Blade Directives
3
+
title: Blade Helpers
4
+
description: Blade Directives and Components
5
5
order: 4
6
6
---
7
7
@@ -46,5 +46,3 @@ To the `:id` prop, you may pass a string, which will be used as-is as the DOM ID
46
46
```
47
47
48
48
Additionally, you may also pass along any prop that is supported by the Turbo Frame custom Element to the `<x-turbo-frame>` Blade component, like `target`, `src`, or `loading`. These are the listed attributes, but any other attribute will also be forwarded to the `<turbo-frame>` tag that will be rendered by the `<x-turbo-frame>` component. For a full list of what's possible to do with Turbo Frames, see the [documentation](https://turbo.hotwired.dev/handbook/frames).
49
-
50
-
[Continue to Helper Functions...](/docs/{{version}}/helper-functions)
# Broadcasting Turbo Streams Over WebSockets With Laravel Echo
8
+
# Broadcasting Turbo Streams
9
9
10
10
So far, we have used Turbo Streams over HTTP to handle the case of updating multiple parts of the page for a single user after a form submission. In addition to that, you may want to broadcast model changes over WebSockets to all users that are viewing the same page. Although nice, **you don't have to use WebSockets if you don't have the need for it. You may still benefit from Turbo Streams over HTTP.**
11
11
@@ -179,7 +179,7 @@ class Comment extends Model
179
179
180
180
This will also automatically hook into the model events, but instead of broadcasting new instances as `append` it will use `prepend`.
181
181
182
-
Secondly, it will send all changes to this model's broadacsting channel, except for when the model is created (since no one would be listening to its direct channel). In our case, we want to direct the broadcasts to the post linked to this model instead. We can achieve that by adding a `$broadcastsTo` property to the model, like so:
182
+
Secondly, it will send all changes to this model's broadcasting channel, except for when the model is created (since no one would be listening to its direct channel). In our case, we want to direct the broadcasts to the post linked to this model instead. We can achieve that by adding a `$broadcastsTo` property to the model, like so:
183
183
184
184
```php
185
185
class Comment extends Model
@@ -230,7 +230,7 @@ class Comment extends Model
230
230
}
231
231
```
232
232
233
-
Newly created models using the auto-broadcasting feature will be broadcasted to a pluralized version of the model's basename. So if you have a `App\Models\PostComment`, you may expect broadcasts of newly created models to be sent to a private channel called `post_comments`. Again, this convention is only valid for newly created models. Updates/Removals will still be sent to the model's own private channel by default using Laravel's convention for channel names. You may want to specify the channel name for newly created models to be broadcasted to with the `stream` key:
233
+
Newly created models using the auto-broadcasting feature will be broadcasted to a pluralized version of the model's basename. So if you have a `App\Models\PostComment`, you may expect broadcasts of newly created models to be sent to a private channel called `post_comments`. Again, this convention is only valid for newly created models. Updates/Removals will still be sent to the model's own private channel by default using Laravel's convention for channel names. You may want to specify the channel name for newly created models to be broadcast to with the `stream` key:
234
234
235
235
```php
236
236
class Comment extends Model
@@ -247,7 +247,7 @@ Having a `$broadcastsTo` property or implementing the `broadcastsTo()` method in
247
247
248
248
## Broadcasting Turbo Streams to Other Users Only
249
249
250
-
As mentioned erlier, you may want to feed the current user with Turbo Streams using HTTP requests and only send the broadcasts to other users. There are a couple ways you can achieve that.
250
+
As mentioned earlier, you may want to feed the current user with Turbo Streams using HTTP requests and only send the broadcasts to other users. There are a couple ways you can achieve that.
251
251
252
252
First, you can chain on the broadcasting methods, like so:
This way, any broadcast that happens inside the scope of the Closure will only be sent to other users.
270
270
271
-
Third, you may use that same method but without the Closure inside a ServiceProvider, for instance, to instruct the package to only send turbo stream broadcasts to other users globally:
271
+
Third, you may use that same method but without the Closure inside a `ServiceProvider`, for instance, to instruct the package to only send turbo stream broadcasts to other users globally:
## Handmade Broadcasting Using The `turbo_stream()` Response Builder
368
368
369
-
Alternatively to use the `TurboStream` Facade (or Factory type-hint), you may also broadcast directly from the `turbo_stream()` function response builder:
369
+
Alternatively to using the `TurboStream` Facade (or Factory type-hint), you may also broadcast directly from the `turbo_stream()` function response builder:
If you don't want to use resource routes, at least consider using the naming convention: render forms in a route name ending in `.create` or `.edit` and name their handler routes ending with `.store` or `.update`.
17
17
18
-
You may want to define exceptions to the route guessing behavior. In that case, you may want to set the `redirect_guessing_exceptions` in the `config/turbo-laravel.php` config file:
18
+
You may define exceptions to the route guessing behavior by setting the `redirect_guessing_exceptions` in the `config/turbo-laravel.php` config file:
19
19
20
20
```php
21
21
return [
@@ -26,16 +26,14 @@ return [
26
26
];
27
27
```
28
28
29
-
When using this config, the redirection behavior will still happen, but the package will not guess routes. See the [Validation Response Redirects](/docs/{{version}}/validation-response-redirects) page to know more about why this happens.
29
+
When using this config, the redirection behavior will still happen, but the package will not guess routes. See the [Validation Response Redirects](/1.x/docs/validation-response-redirects) page to know more about why this happens.
30
30
31
31
## Partials
32
32
33
-
You may want to split up your views in smaller chunks (aka. "partials"), such as `comments/_comment.blade.php` which displays a comment resource, or `comments/_form.blade.php` for the form to either create/update comments. This will allow you to reuse these _partials_ in [Turbo Streams](/docs/{{version}}/turbo-streams).
33
+
You may want to split up your views in smaller chunks (aka. "partials"), such as `comments/_comment.blade.php` which displays a comment resource, or `comments/_form.blade.php` for the form to either create/update comments. This will allow you to reuse these _partials_ in [Turbo Streams](/1.x/docs/turbo-streams).
34
34
35
-
The models' partials (such as the `comments/_comment.blade.php` for a `Comment` model) may only rely on having a single `$comment` instance variable passed to them. That's because the package will, by default, figure out the partial for a given model when broadcasting and will also pass the model to such partial, using the class basename as the variable instance in _camelCase_. Again, that's by default, you can customize most things. Read the [Broadcasting](/docs/{{version}}/broadcasting) section to know more.
35
+
The models' partials (such as the `comments/_comment.blade.php` for a `Comment` model) may only rely on having a single `$comment` instance variable passed to them. That's because the package will, by default, figure out the partial for a given model when broadcasting and will also pass the model to such partial, using the class basename as the variable instance in _camelCase_. Again, that's by default, you can customize most things. Read the [Broadcasting](/1.x/docs/broadcasting) section to know more.
36
36
37
37
## Turbo Stream Channel Names
38
38
39
-
You may use the model's Fully Qualified Class Name (aka. FQCN) as your Broadcasting Channel authorization routes with a wildcard, such as `App.Models.Comment.{comment}` for a `Comment` model living in `App\\Models\\` - the wildcard's name doesn't matter, as long as there is one. This is the default [broadcasting channel naming convention](https://laravel.com/docs/8.x/broadcasting#model-broadcasting-conventions) in Laravel.
40
-
41
-
[Continue to Blade Helpers...](/docs/{{version}}/blade-helpers)
39
+
You may use the model's Fully Qualified Class Name (aka. FQCN) as your Broadcasting Channel authorization routes with a wildcard, such as `App.Models.Comment.{comment}` for a `Comment` model living in `App\\Models\\` - the wildcard's name doesn't matter, as long as there is one. This is the default [broadcasting channel naming convention](https://laravel.com/docs/broadcasting#model-broadcasting-conventions) in Laravel.
Copy file name to clipboardExpand all lines: docs/csrf.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,5 +24,3 @@ Since Turbo.js intercepts form submissions and converts those to fetch requests
24
24
```
25
25
26
26
With that being said, you may still want to use the `@csrf` Blade directive if you want to support users with JavaScript disabled, since the forms will still work if they contain the CSRF token.
27
-
28
-
[Continue to Turbo Native...](/docs/{{version}}/turbo-native)
Copy file name to clipboardExpand all lines: docs/helper-functions.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ dom_class($comment);
35
35
36
36
This function will generate the DOM class named based on your model's classname. If you have an instance of a `App\Models\Comment` model, it will generate a `comment` DOM class.
37
37
38
-
Similarly to the `dom_id()` function, you may also pass a context prefix as the second parameter:
38
+
Similar to the `dom_id()` function, you may also pass a context prefix as the second parameter:
All these functions are also registered globally, so you may use it directly without the `use` statements (this is useful in contexts like Blade views, for instance).
73
-
74
-
[Continue to Turbo Streams...](/docs/{{version}}/turbo-streams)
Copy file name to clipboardExpand all lines: docs/known-issues.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,4 +11,4 @@ If you ever encounter an issue with the package, look here first for documented
11
11
12
12
## Fixing Laravel's Previous URL Issue
13
13
14
-
Visits from Turbo Frames will hit your application and Laravel by default keeps track of previously visited URLs to be used with helpers like `url()->previous()`, for instance. This might be confusing because chances are that you wouldn't want to redirect users to the URL of the most recent Turbo Frame that hit your app. So, to avoid storying Turbo Frames visits as Laravel's previous URL, head to the [issue](https://github.com/tonysm/turbo-laravel/issues/60#issuecomment-1123142591) where a solution was discussed.
14
+
Visits from Turbo Frames will hit your application and Laravel by default keeps track of previously visited URLs to be used with helpers like `url()->previous()`, for instance. This might be confusing because chances are that you wouldn't want to redirect users to the URL of the most recent Turbo Frame that hit your app. So, to avoid storing Turbo Frames visits as Laravel's previous URL, head to the [issue](https://github.com/tonysm/turbo-laravel/issues/60#issuecomment-1123142591) where a solution was discussed.
Copy file name to clipboardExpand all lines: docs/livewire.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,5 +105,3 @@ Now, we can use this element in a page where we want to have the integration bet
105
105
That's it! With that, we got Livewire to generate Turbo Streams, dispatch it as a browser event, which gets intercepted by our custom HTML element and applied to the page!
106
106
107
107
This is only an example of what a deeper integration could look like.
108
-
109
-
[Continue to Validation Response Redirects...](/docs/{{version}}/validation-response-redirects)
Copy file name to clipboardExpand all lines: docs/testing.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,4 @@ class CreatesCommentsTest extends TestCase
149
149
}
150
150
```
151
151
152
-
*Note: If you're using the automatic model changes broadcasting, make sure your `turbo-laravel.queue` config key is set to false, otherwise actions may not be dispatched during test because the model observer only fires them after the transaction is commited, which never happens in tests since they run inside a transaction.*
153
-
154
-
[Continue to Known Issues...](/docs/{{version}}/known-issues)
152
+
*Note: If you're using the automatic model changes broadcasting, make sure your `turbo-laravel.queue` config key is set to false, otherwise actions may not be dispatched during test because the model observer only fires them after the transaction is committed, which never happens in tests since they run inside a transaction.*
0 commit comments