forked from laravel/jetstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInertiaManager.php
49 lines (42 loc) · 1.06 KB
/
InertiaManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Laravel\Jetstream;
use Illuminate\Http\Request;
use Inertia\Inertia;
class InertiaManager
{
/**
* The registered rendering callbacks.
*
* @var array
*/
protected $renderingCallbacks = [];
/**
* Render the given Inertia page.
*
* @param \Illuminate\Http\Request $request
* @param string $page
* @param array $data
* @return \Inertia\Response
*/
public function render(Request $request, string $page, array $data = [])
{
if (isset($this->renderingCallbacks[$page])) {
foreach ($this->renderingCallbacks[$page] as $callback) {
$data = $callback($request, $data);
}
}
return Inertia::render($page, $data);
}
/**
* Register a rendering callback.
*
* @param string $page
* @param callable $callback
* @return $this
*/
public function whenRendering(string $page, callable $callback)
{
$this->renderingCallbacks[$page][] = $callback;
return $this;
}
}