예제 #1
0
 /**
  * Returns a model that have an alias and columns with attributes
  *
  * @return Model
  */
 public function getAnotherModel() : Model
 {
     $model = new ExampleModel();
     $model->setAlias('another_model');
     $id = new Column('id');
     $id->setAutomatic();
     $stock = new Column('stock');
     $stock->setAlias('product_stock')->addFilter(function ($column) {
         return (int) $column;
     });
     $product = new Column('product');
     $product->setAlias('product_name')->setDefault('My name');
     $add = new Column('add');
     $add->setAlias('date_added')->setDefault(new \DateTime())->addSetterFilter(function ($column) {
         return $column instanceof \DateTime ? $column : null;
     })->addGetterFilter(function ($column) {
         return empty($column) ? null : new \DateTime($column);
     });
     $model->addColumn($id);
     $model->addColumn($product);
     return $model;
 }
예제 #2
0
 /**
  * Adds a column to this model
  *
  * @param Column $column
  * @return Model
  */
 protected function addColumn(Column $column) : self
 {
     $this->columns[$column->getId()] = $column;
     return $this;
 }