File tree 3 files changed +71
-1
lines changed
3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public function show(Request $request, $teamId)
29
29
abort (403 );
30
30
}
31
31
32
- return Inertia:: render ('Teams/Show ' , [
32
+ return Jetstream:: inertia ()-> render ($ request , 'Teams/Show ' , [
33
33
'team ' => $ team ->load ('owner ' , 'users ' ),
34
34
'availableRoles ' => array_values (Jetstream::$ roles ),
35
35
'availablePermissions ' => Jetstream::$ permissions ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Laravel \Jetstream ;
4
+
5
+ use Illuminate \Http \Request ;
6
+ use Inertia \Inertia ;
7
+
8
+ class InertiaManager
9
+ {
10
+ /**
11
+ * The registered rendering callbacks.
12
+ *
13
+ * @var array
14
+ */
15
+ protected $ renderingCallbacks = [];
16
+
17
+ /**
18
+ * Render the given Inertia page.
19
+ *
20
+ * @param \Illuminate\Http\Request $request
21
+ * @param string $page
22
+ * @param array $data
23
+ * @return \Inertia\Response
24
+ */
25
+ public function render (Request $ request , string $ page , array $ data = [])
26
+ {
27
+ if (isset ($ this ->renderingCallbacks [$ page ])) {
28
+ foreach ($ this ->renderingCallbacks [$ page ] as $ callback ) {
29
+ $ data = $ callback ($ request , $ data );
30
+ }
31
+ }
32
+
33
+ return Inertia::render ($ page , $ data );
34
+ }
35
+
36
+ /**
37
+ * Register a rendering callback.
38
+ *
39
+ * @param string $page
40
+ * @param callable $callback
41
+ * @return $this
42
+ */
43
+ public function whenRendering (string $ page , callable $ callback )
44
+ {
45
+ $ this ->renderingCallbacks [$ page ][] = $ callback ;
46
+
47
+ return $ this ;
48
+ }
49
+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ class Jetstream
59
59
*/
60
60
public static $ membershipModel = 'App \\Models \\Membership ' ;
61
61
62
+ /**
63
+ * The Inertia manager instance.
64
+ *
65
+ * @var \Laravel\Jetstream\InertiaManager
66
+ */
67
+ public static $ inertiaManager ;
68
+
62
69
/**
63
70
* Determine if Jetstream has registered roles.
64
71
*
@@ -347,6 +354,20 @@ public static function deleteUsersUsing(string $class)
347
354
return app ()->singleton (DeletesUsers::class, $ class );
348
355
}
349
356
357
+ /**
358
+ * Manage Jetstream's Inertia settings.
359
+ *
360
+ * @return \Laravel\Jetstream\InertiaManager
361
+ */
362
+ public static function inertia ()
363
+ {
364
+ if (is_null (static ::$ inertiaManager )) {
365
+ static ::$ inertiaManager = new InertiaManager ;
366
+ }
367
+
368
+ return static ::$ inertiaManager ;
369
+ }
370
+
350
371
/**
351
372
* Configure Jetstream to not register its routes.
352
373
*
You can’t perform that action at this time.
0 commit comments