public function beforeRenderForm($view, $model)
 {
     $selectOtherCategories = [0 => 'Nenhuma'];
     if ($model->id) {
         $categories = ProductCategory::where('id', '!=', $model->id)->get();
     } else {
         $categories = ProductCategory::get();
     }
     foreach ($categories as $category) {
         $selectOtherCategories[$category->id] = $category->fullName;
     }
     $view->with('selectOtherCategories', $selectOtherCategories);
     return $view;
 }
Ejemplo n.º 2
0
 public function makeFields()
 {
     $this->reference = new CharField(['label' => Product::getAttributeName('reference')]);
     $this->name = new CharField(['label' => Product::getAttributeName('name')]);
     $this->price = new FloatField(['label' => Product::getAttributeName('price')]);
     $this->weight = new FloatField(['label' => Product::getAttributeName('weight')]);
     $this->text = new CharField(['label' => Product::getAttributeName('text')]);
     $this->stock = new IntegerField(['label' => Product::getAttributeName('stock')]);
     $this->description = new CharField(['label' => Product::getAttributeName('description')]);
     $this->category_id = new IntegerField(['label' => Product::getAttributeName('category_id')]);
     $this->category_id->setOptions(function () {
         $result = array('' => '');
         foreach (ProductCategory::get() as $category) {
             $result[$category->id] = $category->fullName;
         }
         return $result;
     });
 }