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
The Datastar package for Laravel allows you to handle backend requests by sending SSE events using [Blade directives](#blade-directives) in views _or_[using controllers](#using-controllers). The former requires less setup and is more straightforward, while the latter provides more flexibility.
44
44
45
-
Here’s a trivial example that toggles some backend state using the Blade view `_datastar/toggle.blade.php` to handle the request.
45
+
Here’s a trivial example that toggles some backend state using the Blade view `datastar/toggle.blade.php` to handle the request.
@@ -94,42 +94,48 @@ The `datastar()` helper function is available in Blade views and returns a `Data
94
94
95
95
#### `datastar()->get()`
96
96
97
-
Returns a `@get()` action request to render a view at the given path.
97
+
Returns a `@get()` action request to render a view at the given path. The value can be a file path _or_ a dot-separated path to a Blade view.
98
98
99
99
```php
100
-
{{ datastar()->get('path/to/view') }}
100
+
{{ datastar()->get('path.to.view') }}
101
+
```
102
+
103
+
Variables can be passed into the view using a second argument. Any variables passed in will become available in the rendered view. Variables are tamper-proof yet visible in the source code in plain text, so you should avoid passing in any sensitive data.
Works the same as [`datastar()->get()`](#datastar-get) but returns a `@post()` action request to render a view at the given path. A CSRF token is automatically generated and sent along with the request.
106
112
107
113
```php
108
-
{{ datastar()->post('path/to/view') }}
114
+
{{ datastar()->post('path.to.view') }}
109
115
```
110
116
111
117
#### `datastar()->put()`
112
118
113
119
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@put()` action request.
114
120
115
121
```php
116
-
{{ datastar()->put('path/to/view') }}
122
+
{{ datastar()->put('path.to.view') }}
117
123
```
118
124
119
125
#### `datastar()->patch()`
120
126
121
127
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@patch()` action request.
122
128
123
129
```php
124
-
{{ datastar()->patch('path/to/view') }}
130
+
{{ datastar()->patch('path.to.view') }}
125
131
```
126
132
127
133
#### `datastar()->delete()`
128
134
129
135
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@delete()` action request.
130
136
131
137
```php
132
-
{{ datastar()->delete('path/to/view') }}
138
+
{{ datastar()->delete('path.to.view') }}
133
139
```
134
140
135
141
### Blade Directives
@@ -188,7 +194,7 @@ Redirects the browser by setting the location to the provided URI.
188
194
189
195
### Using Controllers
190
196
191
-
You can send SSE events using your own controller instead of a Blade view using the `DatastarEventStream` trait. Return the `getStreamedResponse()` method, passing a callable into it that sends zero or more SSE events using methods provided.
197
+
You can send SSE events using your own controller _instead_ of the Datastar controller by using the `DatastarEventStream` trait. Return the `getStreamedResponse()` method, passing a callable into it that sends zero or more SSE events using methods provided.
0 commit comments