Skip to content

Commit 1ef7afe

Browse files
committed
Add dot-notation and variables to readme
1 parent d863095 commit 1ef7afe

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ php artisan vendor:publish --tag=public
4242

4343
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.
4444

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.
4646

4747
```html
4848
<div data-signals-enabled="false">
4949
<div data-text="$enabled ? 'ON' : 'OFF'"></div>
50-
<button data-on-click="{{ datastar()->get('_datastar/toggle') }}">
50+
<button data-on-click="{{ datastar()->get('datastar.toggle') }}">
5151
<span id="button-text">Enable</span>
5252
</button>
5353
</div>
5454
```
5555

5656
```php
57-
{{-- _datastar/toggle.blade.php --}}
57+
{{-- datastar/toggle.blade.php --}}
5858

5959
@php
6060
$enabled = $signals->enabled;
@@ -94,42 +94,48 @@ The `datastar()` helper function is available in Blade views and returns a `Data
9494

9595
#### `datastar()->get()`
9696

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.
9898

9999
```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.
104+
105+
```php
106+
{{ datastar()->get('path.to.view', ['offset' => 10]) }}
101107
```
102108

103109
#### `datastar()->post()`
104110

105111
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.
106112

107113
```php
108-
{{ datastar()->post('path/to/view') }}
114+
{{ datastar()->post('path.to.view') }}
109115
```
110116

111117
#### `datastar()->put()`
112118

113119
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@put()` action request.
114120

115121
```php
116-
{{ datastar()->put('path/to/view') }}
122+
{{ datastar()->put('path.to.view') }}
117123
```
118124

119125
#### `datastar()->patch()`
120126

121127
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@patch()` action request.
122128

123129
```php
124-
{{ datastar()->patch('path/to/view') }}
130+
{{ datastar()->patch('path.to.view') }}
125131
```
126132

127133
#### `datastar()->delete()`
128134

129135
Works the same as [`datastar()->post()`](#datastar-post) but returns a `@delete()` action request.
130136

131137
```php
132-
{{ datastar()->delete('path/to/view') }}
138+
{{ datastar()->delete('path.to.view') }}
133139
```
134140

135141
### Blade Directives
@@ -188,7 +194,7 @@ Redirects the browser by setting the location to the provided URI.
188194

189195
### Using Controllers
190196

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.
192198

193199
```php
194200
// routes/web.php

examples/hello-world/resources/views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</label>
2222
<input data-bind-delay id="delay" type="number" step="100" min="0" class="w-36 rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-sky-500 focus:outline focus:outline-sky-500 dark:disabled:border-gray-700 dark:disabled:bg-gray-800/20" />
2323
</div>
24-
<button data-on-click="{{ datastar()->get('_datastar/hello-world') }}" class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer">
24+
<button data-on-click="{{ datastar()->get('datastar.hello-world') }}" class="rounded-md bg-sky-500 px-5 py-2.5 leading-5 font-semibold text-white hover:bg-sky-700 hover:text-gray-100 cursor-pointer">
2525
Start
2626
</button>
2727
</div>

0 commit comments

Comments
 (0)