File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1313use Illuminate \Database \Eloquent \Builder ;
1414use Illuminate \Database \Eloquent \Model ;
1515use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
16+ use Illuminate \Database \Eloquent \SoftDeletingScope ;
1617use Illuminate \Support \Arr ;
1718use Illuminate \Support \Collection ;
1819use Illuminate \Support \Str ;
@@ -172,6 +173,16 @@ public static function table(Table $table): Table
172173 Tables \Actions \DeleteBulkAction::make (),
173174 ])->iconButton (),
174175 ])
176+ ->checkIfRecordIsSelectableUsing (function (DocumentType |Model $ record ) {
177+ $ hasContent = $ record ->content ()->withoutGlobalScopes ([
178+ SoftDeletingScope::class,
179+ ])->count () > 0 ;
180+ if ($ hasContent ) {
181+ // Disallow delete this document type if have content
182+ return false ;
183+ }
184+ return true ;
185+ })
175186 ->filters ([
176187 Tables \Filters \TernaryFilter::make ('show_as_table ' )
177188 ->label (__ ('inspirecms::resources/document-type.show_as_table.label ' )),
Original file line number Diff line number Diff line change @@ -32,12 +32,12 @@ public function saving($model)
3232 */
3333 public function deleting ($ model )
3434 {
35- $ content = $ model ->content ()->withoutGlobalScopes ([
35+ $ hasContent = $ model ->content ()->withoutGlobalScopes ([
3636 SoftDeletingScope::class,
37- ])->get () ;
37+ ])->count () > 0 ;
3838
3939 // Guard: If there is any content, then prevent deleting.
40- if ($ content -> isNotEmpty () ) {
40+ if ($ hasContent ) {
4141 throw new \Exception ('Cannot delete this document type because it has content. ' );
4242 }
4343 }
You can’t perform that action at this time.
0 commit comments