Skip to content

Conversation

@andreia
Copy link
Member

@andreia andreia commented Jan 30, 2026

Details

Allow nullable material on step.


Note

Medium Risk
Includes a schema change to nullable morph columns and corresponding UI/runtime behavior changes; risk is mainly around migration compatibility and ensuring existing steps still render/validate as expected.

Overview
Steps can now be created without an attached material (text-only steps).

This adds a migration to make lms_steps.material_type and material_id nullable and wires it into the package migrations list, updates the material selector form to allow a null material_type while only requiring material_id when a type is chosen, and adjusts the step page to treat material_type = null as an intentional “next-only” step while still showing an error when a type is set but the related material record is missing. The StepFactory gains withoutMaterial() and withText() helpers, and the Step model phpdoc is updated for nullable material fields.

Written by Cursor Bugbot for commit cd81152. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issues.

- Bug 1: In step.blade.php, distinguish between intentionally text-only steps
  (material_type is null) and steps with deleted material (material_type is set
  but material record doesn't exist). Now shows error for deleted material
  regardless of whether text exists.

- Bug 2: In MorphToSelectWithCreate.php, change material_id from nullable() to
  requiredWith('material_type') to prevent invalid state where material_type is
  selected but material_id is null.
@cursor
Copy link

cursor bot commented Jan 30, 2026

Bugbot Autofix prepared a fix for 2 of the 2 bugs found in the latest run.

  • ✅ Fixed: Deleted material silently hidden when step has text
    • Changed logic to check material_type first: null means intentional text-only step, set but with null material means deleted content and error is now shown regardless of text presence.
  • ✅ Fixed: Form allows material_type without selecting actual material
    • Changed material_id validation from nullable() to requiredWith('material_type') to ensure material_id is required when material_type is selected.

Create PR

Or push these changes by commenting:

@cursor push d2b7e39a1c
Preview (d2b7e39a1c)
diff --git a/resources/views/pages/step.blade.php b/resources/views/pages/step.blade.php
--- a/resources/views/pages/step.blade.php
+++ b/resources/views/pages/step.blade.php
@@ -111,23 +111,21 @@
     }
     </style>
 
-    @if (is_null($step->material))
-        @if(!$step->text)
-            {{-- No material and no text: show error --}}
-            <div class="flex items-center justify-center min-h-[60vh]">
-                <x-filament::card class="py-12 w-full max-w-md">
-                    <div class="flex flex-col justify-center items-center text-center">
-                        <div class="mb-4 text-lg font-semibold text-red-600">
-                            The material for this step is missing or has been deleted.
-                        </div>
-                        <x-filament-lms::next-button :fixed="false" />
+    @if (is_null($step->material_type))
+        {{-- Intentionally text-only step: show the next button --}}
+        <x-filament-lms::next-button />
+    @elseif (is_null($step->material))
+        {{-- Material type is set but material is missing (deleted): show error --}}
+        <div class="flex items-center justify-center min-h-[60vh]">
+            <x-filament::card class="py-12 w-full max-w-md">
+                <div class="flex flex-col justify-center items-center text-center">
+                    <div class="mb-4 text-lg font-semibold text-red-600">
+                        The material for this step is missing or has been deleted.
                     </div>
-                </x-filament::card>
-            </div>
-        @else
-            {{-- Text-only step: show the next button --}}
-            <x-filament-lms::next-button />
-        @endif
+                    <x-filament-lms::next-button :fixed="false" />
+                </div>
+            </x-filament::card>
+        </div>
     @elseif ($step->material_type == 'video')
         <livewire:video-step :step="$step"/>
     @elseif ($step->material_type == 'form')

diff --git a/src/Forms/Components/MorphToSelectWithCreate.php b/src/Forms/Components/MorphToSelectWithCreate.php
--- a/src/Forms/Components/MorphToSelectWithCreate.php
+++ b/src/Forms/Components/MorphToSelectWithCreate.php
@@ -62,7 +62,7 @@
                     return $className::query()->pluck('name', 'id');
                 })
                 ->searchable()
-                ->nullable()
+                ->requiredWith('material_type')
                 ->suffixActions([
                     Action::make('create_video')
                         ->label('New')

@andreia
Copy link
Member Author

andreia commented Jan 30, 2026

@cursor push d2b7e39

@cursor
Copy link

cursor bot commented Jan 30, 2026

Could not push Autofix changes. The PR branch may have changed since the Autofix ran, or the Autofix commit may no longer exist.

@swilla
Copy link
Member

swilla commented Jan 30, 2026

Scott is good with this approach

@swilla swilla merged commit d03a2a3 into 4.x Jan 30, 2026
8 checks passed
@swilla swilla deleted the allow_nullable_material_on_step branch January 30, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants