| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace CodexShaper\DBM\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use CodexShaper\DBM\Database\Schema\Table; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use CodexShaper\DBM\Facades\Manager as DBM; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class CrudController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * Load all crud tables. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function index() | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         return view('dbm::app'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * Create|Update CRUD. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function storeOrUpdate(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         if ($request->ajax()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $table = $request->object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             $columns = $request->fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             $permission = $request->isCrudExists ? 'update' : 'create'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             if (($response = DBM::authorize('crud.'.$permission)) !== true) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             if (($response = $this->makeModel($table)) !== true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             if (! class_exists($table['controller'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 DBM::makeController($table['controller']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 if ($object = $this->addOrUpdateObject($table)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     $this->addMenu($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     foreach ($columns as $column) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                         $this->addOrUpdateField($column, $object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 return response()->json([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     'success' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     'object' => $request->object, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     'fields' => $request->fields, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 return $this->generateError([$e->getMessage()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         return response()->json(['success' => false]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * Create a new model if not exists. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param array $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return \Illuminate\Http\JsonResponse|true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function makeModel($table) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         if (empty($table['model'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             return $this->generateError(['Model Must be provided']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         if ($table['makeModel'] && ! class_exists($table['model'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             DBM::makeModel($table['model'], $table['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         if (! $table['makeModel'] && ! class_exists($table['model'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $error = "Create model {$table['model']} first or checked create model option"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             return $this->generateError([$error]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * Create|Update Object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param array $table | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return \CodexShaper\DBM\Models\DBM_Object|\CodexShaper\DBM\Models\DBM_MongoObject|false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function addOrUpdateObject($table) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $object = DBM::Object()->where('name', $table['name'])->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $action = 'update'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         if (! $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             $object = DBM::Object(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             $object->name = $table['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $action = 'save'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $object->slug = Str::slug($table['slug']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $object->display_name = ucfirst($table['display_name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $object->model = $table['model']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $object->controller = $table['controller']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $object->details = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             'findColumn' => $table['findColumn'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             'searchColumn' => $table['searchColumn'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             'perPage' => $table['perPage'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             'orderColumn' => $table['orderColumn'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             'orderDisplayColumn' => $table['orderDisplayColumn'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             'orderDirection' => $table['orderDirection'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         if ($object->{$action}()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             return $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * Create Menu. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * @param \CodexShaper\DBM\Models\DBM_Object|\CodexShaper\DBM\Models\DBM_MongoObject $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * @return true|false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     public function addMenu($object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $menu = DBM::Menu()::where('slug','admin')->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         if(! $menu) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $order = DBM::Menu()::max('order'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             $menu = DBM::Menu(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             $menu->name = "Admin"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             $menu->slug = Str::slug('Admin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             $menu->url = '/admin'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             $menu->order = $order+1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             $menu->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         if(! DBM::MenuItem()::where('slug', Str::slug($object->name))->first()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             $itemOrder = DBM::MenuItem()::max('order'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             $menuItem = DBM::MenuItem(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             $menuItem->menu_id = $menu->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $menuItem->title = $object->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $menuItem->slug = Str::slug($object->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             $menuItem->url = '/database/record/'.$object->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $menuItem->parent_id = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $menuItem->order = $itemOrder+1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $menuItem->route = 'record'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $menuItem->params = '{"tableName":"'.$object->name.'"}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $menuItem->middleware = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $menuItem->controller = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             $menuItem->target = '_self'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $menuItem->icon = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $menuItem->custom_class = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             if($menuItem->save()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * Remove Menu. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @param \CodexShaper\DBM\Models\DBM_Object|\CodexShaper\DBM\Models\DBM_MongoObject $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @return true|false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     public function removeMenu($slug) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $menu = Menu::where('slug', 'admin')->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         if($menuItem = MenuItem::where(['slug' => $slug, 'menu_id' => $menu->id])->first()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             $menuItem->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * Create|Update Object Field. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * @param array $column | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @param \CodexShaper\DBM\Models\DBM_Object|\CodexShaper\DBM\Models\DBM_MongoObject $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |      * @return \CodexShaper\DBM\Models\DBM_Field|\CodexShaper\DBM\Models\DBM_MongoField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     public function addOrUpdateField($column, $object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         $field = DBM::Field()->where([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             'dbm_object_id' => $object->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             'name' => $column['name'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         ])->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $action = 'update'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         if (! $field) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |             $field = DBM::Field(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             $field->dbm_object_id = $object->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |             $field->name = $column['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             $action = 'save'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         $field->display_name = ucfirst($column['display_name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         $field->type = $column['type']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         $field->create = isset($column['create']) ? $column['create'] : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         $field->read = isset($column['read']) ? $column['read'] : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         $field->edit = isset($column['edit']) ? $column['edit'] : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         $field->delete = isset($column['delete']) ? $column['delete'] : false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         $field->order = $column['order']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         $field->function_name = isset($column['function_name']) ? $column['function_name'] : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         $field->settings = json_decode($column['settings']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         $field->{$action}(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |      * Delete CRUD. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     public function delete(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         if ($request->ajax()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |             if (($response = DBM::authorize('crud.delete')) !== true) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 return $response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             $object = DBM::Object()->where('name', $request->table)->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |             if ($object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |                 $this->removeMenu($object->slug); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |                 $object->fields()->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |                 $object->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |                 return response()->json(['success' => true]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         return response()->json(['success' => false]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |      * Generate an error. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |      * @param array $errors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     protected function generateError($errors) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         return response()->json([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |             'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             'errors' => $errors, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         ], 400); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 271 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 272 |  |  |  |