Пример #1
0
 protected function onAJAX(\Controllers\Request $input)
 {
     $search = $input->get('search');
     if ('' == $search) {
         return Plant::all()->toArray();
     }
     $plants = Plant::where('name', 'LIKE', $search . '%')->orWhere('scientific', 'LIKE', $search . '%');
     if ($plants->count()) {
         return $plants->get()->toArray();
     }
     $plants = Plant::where('name', 'LIKE', '%' . $search . '%')->orWhere('scientific', 'LIKE', '%' . $search . '%');
     return $plants->get()->toArray();
 }
Пример #2
0
 protected function onPost(\Controllers\Request $input)
 {
     $id = $input->get('id');
     $this->data['update_success'] = false;
     try {
         $obj = Order::createFromInput($input, $id);
         $this->data['update_success'] = true;
     } catch (\App\Exceptions\Validation $ex) {
         $this->data['errors'] = $ex->validator->errors();
     } catch (\Exception $ex) {
         $this->errors->add('update-error', $ex->getMessage());
     }
     return parent::onPost($input);
 }
Пример #3
0
 protected function onPost(\Controllers\Request $input)
 {
     $id = $input->get('id');
     $this->data['update_success'] = false;
     try {
         Module::find($id)->delete();
         $this->data['delete_success'] = true;
         return $this->redirect($this->plugin->modules_url());
     } catch (\App\Exceptions\Validation $ex) {
         $this->data['errors'] = $ex->validator->errors();
     } catch (\Exception $ex) {
         $this->errors->add('delete-error', $ex->getMessage());
     }
     return parent::onPost($input);
 }
Пример #4
0
 protected function onPost(\Controllers\Request $input)
 {
     $id = $input->get('id');
     $this->data['update_success'] = false;
     try {
         Soil::find($id)->delete();
         $this->data['delete_success'] = true;
         $this->view = 'admin.soil.index';
         $this->data['soil_types'] = Soil::all();
     } catch (\Exceptions\Validation $ex) {
         $this->data['errors'] = $ex->validator->errors();
     } catch (\Exception $ex) {
         $this->errors->add('delete-error', $ex->getMessage());
     }
     return parent::onPost($input);
 }
Пример #5
0
 public function getCropFit(\Controllers\Request $input, $hash)
 {
     /* @var $dbImage ImageModel */
     $dbImage = ImageModel::whereHash($hash)->first();
     if (!$dbImage) {
         abort(404);
     }
     $status = 200;
     try {
         $content = $dbImage->getCropFit($input->all());
         $headers = ['Content-Type' => $dbImage->getMime()];
     } catch (\Exception $ex) {
         dd($ex);
         abort(404);
     }
     return response($content, $status, $headers);
 }
Пример #6
0
 public function getModules(Request $input)
 {
     $query = \App\Models\Module::query();
     if ($input->has('id')) {
         $id = $input->get('id');
         if (is_array($id)) {
             $query->whereIn('modules.id', $id);
         } else {
             $query->where('modules.id', $id);
         }
     }
     if ($input->has('category_id')) {
         $id = $input->get('category_id');
         $query->leftJoin('modules_categories', 'modules.id', '=', 'modules_categories.module_id');
         if (is_array($id)) {
             $query->whereIn('modules_categories.category_id', $id);
         } else {
             $query->where('modules_categories.category_id', $id);
         }
     }
     $fullModules = $query->select('modules.*')->with('categories')->get();
     $moduleIDs = $fullModules->lists('id');
     $responseImages = [];
     /* SELECT
        mp.module_id,
        SUM(mp.amount * p.price)
        FROM homestead.module_plants as mp
        LEFT JOIN homestead.plants as p on mp.plant_id = p.id
        GROUP BY mp.module_id
        ; */
     $dbPricesQuery = \DB::table('module_plants AS mp')->leftJoin('plants AS p', 'mp.plant_id', '=', 'p.id')->select(['mp.module_id', \DB::raw('SUM(mp.amount * p.price) AS price')])->whereIn('mp.module_id', $moduleIDs)->groupBy('mp.module_id');
     $dbPrices = $dbPricesQuery->get();
     $prices = [];
     foreach ($dbPrices as $price) {
         $prices[$price->module_id] = $price->price;
     }
     /** @var Module $module */
     foreach ($fullModules as $module) {
         $responseImages[$module->id] = ['id' => $module->id, 'top_image' => $module->top_image_hash, 'front_image' => $module->front_image_hash, 'mature_front_image' => $module->mature_front_image_hash, 'price' => array_get($prices, $module->id, 0), 'height' => $module->height, 'width' => $module->width, 'categories' => $module->categories->lists('slug', 'id')];
     }
     return response(json_encode($responseImages, JSON_FORCE_OBJECT), 200, ['Content-Type' => 'application/json']);
 }