12
12
use Illuminate \Contracts \Support \Responsable ;
13
13
use Illuminate \Contracts \View \View ;
14
14
use Illuminate \Database \Eloquent \Model ;
15
+ use Illuminate \Support \Arr ;
15
16
use Illuminate \Support \HtmlString ;
16
17
use Illuminate \Support \Traits \Macroable ;
17
18
@@ -37,7 +38,7 @@ class PendingTurboStreamResponse implements Htmlable, Renderable, Responsable
37
38
38
39
public static function forModel (Model $ model , ?string $ action = null ): self
39
40
{
40
- $ builder = new self () ;
41
+ $ builder = new self ;
41
42
42
43
// We're treating soft-deleted models as they were deleted. In other words, we
43
44
// will render the remove Turbo Stream. If you need to treat a soft-deleted
@@ -108,6 +109,22 @@ public function attributes(array $attributes): self
108
109
return $ this ;
109
110
}
110
111
112
+ public function morph (): self
113
+ {
114
+ return $ this ->method ('morph ' );
115
+ }
116
+
117
+ public function method (?string $ method = null ): self
118
+ {
119
+ if ($ method ) {
120
+ return $ this ->attributes (array_merge ($ this ->useCustomAttributes , [
121
+ 'method ' => $ method ,
122
+ ]));
123
+ }
124
+
125
+ return $ this ->attributes (Arr::except ($ this ->useCustomAttributes , 'method ' ));
126
+ }
127
+
111
128
public function append (Model |string $ target , $ content = null ): self
112
129
{
113
130
return $ this ->buildAction (
@@ -267,8 +284,7 @@ private function buildActionAll(string $action, Model|string $targets, $content
267
284
268
285
public function broadcastTo ($ channel , ?callable $ callback = null )
269
286
{
270
- $ callback = $ callback ?? function () {
271
- };
287
+ $ callback = $ callback ?? function () {};
272
288
273
289
return tap ($ this , function () use ($ channel , $ callback ) {
274
290
$ callback ($ this ->asPendingBroadcast ($ channel ));
@@ -277,8 +293,7 @@ public function broadcastTo($channel, ?callable $callback = null)
277
293
278
294
public function broadcastToPrivateChannel ($ channel , ?callable $ callback = null )
279
295
{
280
- $ callback = $ callback ?? function () {
281
- };
296
+ $ callback = $ callback ?? function () {};
282
297
283
298
return $ this ->broadcastTo (null , function (PendingBroadcast $ broadcast ) use ($ channel , $ callback ) {
284
299
$ broadcast ->toPrivateChannel ($ channel );
@@ -288,8 +303,7 @@ public function broadcastToPrivateChannel($channel, ?callable $callback = null)
288
303
289
304
public function broadcastToPresenceChannel ($ channel , ?callable $ callback = null )
290
305
{
291
- $ callback = $ callback ?? function () {
292
- };
306
+ $ callback = $ callback ?? function () {};
293
307
294
308
return $ this ->broadcastTo (null , function (PendingBroadcast $ broadcast ) use ($ channel , $ callback ) {
295
309
$ callback ($ broadcast ->toPresenceChannel ($ channel ));
0 commit comments