File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ public function __construct(TurboStreamModelRenderer $renderer)
1616
1717 public function handle (Model $ model , string $ action = null )
1818 {
19- if (! $ model ->exists ) {
19+ if (! $ model ->exists ||
20+ (method_exists ($ model , 'trashed ' ) && $ model ->trashed ())
21+ ) {
2022 return $ this ->renderModelDeletedStream ($ model );
2123 }
2224
Original file line number Diff line number Diff line change 22
33namespace Tonysm \TurboLaravel \Tests \Http ;
44
5+ use Illuminate \Database \Eloquent \SoftDeletes ;
56use Illuminate \Support \Facades \View ;
67use Tonysm \TurboLaravel \Models \Broadcasts ;
78use Tonysm \TurboLaravel \Tests \TestCase ;
@@ -111,6 +112,21 @@ public function streams_model_on_delete()
111112 $ this ->assertEquals (Turbo::TURBO_STREAM_FORMAT , $ resp ->headers ->get ('Content-Type ' ));
112113 }
113114
115+ /** @test */
116+ public function streams_model_on_soft_delete ()
117+ {
118+ $ testModelSoftDelete = tap (TestModelSoftDelete::create (['name ' => 'test ' ]))->delete ();
119+
120+ $ expected = <<<html
121+ <turbo-stream target="test_model_soft_delete_ {$ testModelSoftDelete ->getKey ()}" action="remove"></turbo-stream>
122+ html ;
123+
124+ $ resp = response ()->turboStream ($ testModelSoftDelete );
125+
126+ $ this ->assertEquals ($ expected , trim ($ resp ->getContent ()));
127+ $ this ->assertEquals (Turbo::TURBO_STREAM_FORMAT , $ resp ->headers ->get ('Content-Type ' ));
128+ }
129+
114130 /** @test */
115131 public function streams_broadcastable_models_for_deleted ()
116132 {
@@ -190,6 +206,16 @@ public function hotwirePartialName()
190206 }
191207}
192208
209+ class TestModelSoftDelete extends TestModel
210+ {
211+ use SoftDeletes;
212+
213+ public function hotwirePartialName ()
214+ {
215+ return "_test_model_soft_delete " ;
216+ }
217+ }
218+
193219class BroadcastTestModel extends \Tonysm \TurboLaravel \Tests \TestModel
194220{
195221 use Broadcasts;
Original file line number Diff line number Diff line change 1+ <div id =" @domid ($testModelSoftDelete )" >hello</div >
You can’t perform that action at this time.
0 commit comments