@@ -209,6 +209,107 @@ data() {
209
209
}
210
210
}
211
211
```
212
+ ### Usage with Jetstream (Vue/Inertia)
213
+
214
+ To make things work follow this steps:
215
+
216
+ 1 . Add ` \Spatie\Honeypot\ProtectAgainstSpam::class ` to ` bootstrap/app.php ` in ` ->withMiddleware ` block. For example:
217
+
218
+ ``` php
219
+ $middleware->web(append: [
220
+ \App\Http\Middleware\HandleInertiaRequests::class,
221
+ \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
222
+
223
+ // will silenty reload Login page
224
+ \Spatie\Honeypot\ProtectAgainstSpam::class, // <- this
225
+ ]);
226
+ ```
227
+
228
+ or
229
+
230
+ ```php
231
+ $middleware- >web(append: [
232
+ \App\Http\Middleware\HandleInertiaRequests::class,
233
+ \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
234
+ ]);
235
+
236
+ // will show blank responce page in iframe inside modal
237
+ $middleware->append(\Spatie\Honeypot\ProtectAgainstSpam::class);
238
+ ```
239
+
240
+ 2 . Add ` honeypot ` variable to share block of ` app/Http/Middleware/HandleInertiaRequests.php ` middleware. For example:
241
+
242
+ ``` php
243
+ public function share(Request $request): array
244
+ {
245
+ return array_merge(parent::share($request), [
246
+ // read more here https://laravel.com/docs/11.x/authorization#authorization-and-inertia
247
+ 'honeypot' => new \Spatie\Honeypot\Honeypot(config('honeypot'))
248
+ ]);
249
+ }
250
+ ```
251
+
252
+ 3 . Add honeypot elements to ` Pages ` you want. For example ` resourses/js/Pages/Auth/Login.vue ` like this:
253
+
254
+ Redefine props like this:
255
+
256
+ ``` javascript
257
+ const props = defineProps ({
258
+ canResetPassword: Boolean ,
259
+ status: String ,
260
+ honeypot: Object ,
261
+ });
262
+ ```
263
+
264
+ Redefine ` form ` like this:
265
+
266
+ ``` javascript
267
+ const form = useForm ({
268
+ email: ' ' ,
269
+ password: ' ' ,
270
+ remember: false ,
271
+ [props .honeypot .nameFieldName ]: ' ' ,
272
+ [props .honeypot .validFromFieldName ]: props .honeypot .encryptedValidFrom ,
273
+ });
274
+ ```
275
+
276
+ And add html to ` template ` , like this:
277
+
278
+ ``` html
279
+ <div v-if =" honeypot.enabled" :name =" `${honeypot.nameFieldName}_wrap`" style =" display : none ;" >
280
+ <input type =" text" v-model =" form[honeypot.nameFieldName]" :name =" honeypot.nameFieldName" :id =" honeypot.nameFieldName" />
281
+ <input type =" text" v-model =" form[honeypot.validFromFieldName]" :name =" honeypot.validFromFieldName" />
282
+ </div >
283
+ ```
284
+
285
+ In ` Register.vue ` changes will be:
286
+
287
+ ``` javascript
288
+ const props = defineProps ({
289
+ honeypot: Object ,
290
+ });
291
+
292
+ const form = useForm ({
293
+ name: ' ' ,
294
+ email: ' ' ,
295
+ password: ' ' ,
296
+ password_confirmation: ' ' ,
297
+ terms: false ,
298
+ [props .honeypot .nameFieldName ]: ' ' ,
299
+ [props .honeypot .validFromFieldName ]: props .honeypot .encryptedValidFrom ,
300
+ });
301
+ ```
302
+
303
+ and
304
+
305
+ ``` html
306
+ <div v-if =" honeypot.enabled" :name =" `${honeypot.nameFieldName}_wrap`" style =" display : none ;" >
307
+ <input type =" text" v-model =" form[honeypot.nameFieldName]" :name =" honeypot.nameFieldName" :id =" honeypot.nameFieldName" />
308
+ <input type =" text" v-model =" form[honeypot.validFromFieldName]" :name =" honeypot.validFromFieldName" />
309
+ </div >
310
+ ```
311
+
312
+ That's all.
212
313
213
314
### Usage in Livewire
214
315
0 commit comments