55use App \Http \Requests \MonsterRequest as StoreRequest ;
66// VALIDATION: change the requests to match your own file names if you need form validation
77use Backpack \CRUD \app \Http \Controllers \CrudController ;
8+ use Backpack \CRUD \app \Library \Widget ;
89use Illuminate \Support \Collection ;
910
1011class MonsterCrudController extends CrudController
1112{
1213 use \Backpack \CRUD \app \Http \Controllers \Operations \ListOperation;
1314 use \Backpack \CRUD \app \Http \Controllers \Operations \CreateOperation;
1415 use \Backpack \CRUD \app \Http \Controllers \Operations \UpdateOperation;
16+ use \Backpack \DataformModal \Http \Controllers \Operations \CreateInModalOperation;
17+ use \Backpack \DataformModal \Http \Controllers \Operations \UpdateInModalOperation;
1518 use \Backpack \CRUD \app \Http \Controllers \Operations \DeleteOperation;
1619 use \Backpack \CRUD \app \Http \Controllers \Operations \ShowOperation;
1720 use \Backpack \CRUD \app \Http \Controllers \Operations \FetchOperation;
18- use \Backpack \Pro \Http \Controllers \Operations \DropzoneOperation { dropzoneUpload as traitDropzone ; }
19- use \ App \ Http \ Controllers \ Admin \ Operations \SMSOperation; //Custom Form Operation Example
21+ use \Backpack \Pro \Http \Controllers \Operations \AjaxUploadOperation { ajaxUpload as traitAjaxUpload ; }
22+ use Operations \SMSOperation; //Custom Form Operation Example
2023 use \Backpack \ActivityLog \Http \Controllers \Operations \ModelActivityOperation;
2124 use \Backpack \ActivityLog \Http \Controllers \Operations \EntryActivityOperation;
2225
@@ -131,10 +134,10 @@ public function setupListOperation()
131134 'element ' => 'span ' ,
132135 'class ' => function ($ crud , $ column , $ entry , $ related_key ) {
133136 if ($ column ['text ' ] == 'Yes ' ) {
134- return 'badge rounded-pill bg-success ' ;
137+ return 'badge rounded-pill bg-success text-white ' ;
135138 }
136139
137- return 'badge rounded-pill bg-danger ' ;
140+ return 'badge rounded-pill bg-danger text-white ' ;
138141 },
139142 ],
140143 ],
@@ -279,6 +282,53 @@ public function setupListOperation()
279282
280283 public function setupShowOperation ()
281284 {
285+ // add a widget
286+ Widget::add ([
287+ 'type ' => 'datatable ' ,
288+ 'controller ' => 'App\Http\Controllers\Admin\IconCrudController ' ,
289+ 'name ' => 'icon_crud ' ,
290+ 'section ' => 'after_content ' ,
291+ 'content ' => [
292+ 'header ' => 'Icons for this monster ' ,
293+ ],
294+ 'wrapper ' => ['class ' => 'mb-3 ' ],
295+ ]);
296+
297+ Widget::add ([
298+ 'type ' => 'datatable ' ,
299+ 'controller ' => 'App\Http\Controllers\Admin\ProductCrudController ' ,
300+ 'name ' => 'products_datatable ' ,
301+ 'section ' => 'after_content ' ,
302+ 'content ' => [
303+ 'header ' => 'Products for this monster ' ,
304+ ],
305+ 'wrapper ' => ['class ' => 'mb-3 ' ],
306+ 'configure ' => function ($ crud , $ entry = null ) {
307+ // Customize which columns to show
308+ $ crud ->removeAllColumns ();
309+ $ crud ->addColumn (['name ' => 'name ' , 'label ' => 'Product Name ' ]);
310+ $ crud ->addColumn (['name ' => 'price ' , 'label ' => 'Price ' ]);
311+
312+ // Get the current monster's products
313+ if ($ entry ) {
314+ $ productIds = $ entry ->products ->pluck ('id ' )->toArray ();
315+ if (count ($ productIds ) > 0 ) {
316+ // Configure the controller to only show products related to this monster
317+ $ crud ->addClause ('whereIn ' , 'id ' , $ productIds );
318+ } else {
319+ // Force an empty result when there are no products
320+ $ crud ->addClause ('where ' , 'id ' , 0 ); // This will match no products
321+ }
322+
323+ // Remove buttons that aren't needed for this embedded view
324+
325+ // Disable features that aren't needed
326+ $ crud ->denyAccess (['create ' , 'update ' , 'delete ' ]);
327+ $ crud ->disableResponsiveTable ();
328+ }
329+ },
330+ ]);
331+
282332 $ this ->crud ->setOperationSetting ('tabsEnabled ' , true );
283333 $ this ->setupListOperation ();
284334
@@ -320,13 +370,6 @@ public function setupShowOperation()
320370 'tab ' => 'WYSIWYG Editors ' ,
321371 ]);
322372
323- $ this ->crud ->addColumn ([
324- 'name ' => 'wysiwyg ' ,
325- 'type ' => 'wysiwyg ' ,
326- 'label ' => 'Wysiwyg ' .backpack_pro_badge (),
327- 'tab ' => 'WYSIWYG Editors ' ,
328- ]);
329-
330373 $ this ->crud ->addColumn ([
331374 'name ' => 'features ' ,
332375 'label ' => 'Features ' .backpack_pro_badge (),
@@ -1703,10 +1746,11 @@ public static function getFieldsArrayForWysiwygEditorsTab()
17031746 'tab ' => 'WYSIWYG Editors ' ,
17041747 ],
17051748 [ // Summernote
1706- 'name ' => 'summernote ' ,
1707- 'label ' => 'Summernote editor ' .backpack_free_badge (),
1708- 'type ' => 'summernote ' ,
1709- 'tab ' => 'WYSIWYG Editors ' ,
1749+ 'name ' => 'summernote ' ,
1750+ 'label ' => 'Summernote editor ' .backpack_free_badge (),
1751+ 'type ' => 'summernote ' ,
1752+ 'tab ' => 'WYSIWYG Editors ' ,
1753+ 'withFiles ' => true ,
17101754 ],
17111755 [ // CKEditor
17121756 'name ' => 'ckeditor ' ,
@@ -1720,12 +1764,6 @@ public static function getFieldsArrayForWysiwygEditorsTab()
17201764 'type ' => 'tinymce ' ,
17211765 'tab ' => 'WYSIWYG Editors ' ,
17221766 ],
1723- [ // Wysiwyg
1724- 'name ' => 'wysiwyg ' ,
1725- 'label ' => 'Wysiwyg ' .backpack_pro_badge (),
1726- 'type ' => 'wysiwyg ' ,
1727- 'tab ' => 'WYSIWYG Editors ' ,
1728- ],
17291767 ];
17301768 }
17311769
@@ -1837,15 +1875,17 @@ public static function getFieldsArrayForMiscellaneousTab()
18371875 ];
18381876 }
18391877
1840- public function dropzoneUpload ()
1878+ public function ajaxUpload ()
18411879 {
18421880 if (app ('env ' ) === 'production ' ) {
18431881 return response ()->json (['errors ' => [
1844- 'dropzone ' => ['Uploads are disabled in production ' ],
1882+ 'dropzone ' => ['Uploads are disabled in production ' ],
1883+ 'easymde ' => ['Uploads are disabled in production ' ],
1884+ 'summernote ' => ['Uploads are disabled in production ' ],
18451885 ],
18461886 ], 500 );
18471887 }
18481888
1849- return $ this ->traitDropzone ();
1889+ return $ this ->traitAjaxUpload ();
18501890 }
18511891}
0 commit comments