Example #1
0
 /**
  * Test the Model::to_array method.
  *
  * @group laravel
  */
 public function testConvertingToArray()
 {
     Model::$hidden = array('password', 'hidden');
     $array = array('name' => 'Taylor', 'age' => 25, 'password' => 'laravel', 'null' => null);
     $model = new Model($array);
     $first = new Model(array('first' => 'foo', 'password' => 'hidden'));
     $second = new Model(array('second' => 'bar', 'password' => 'hidden'));
     $third = new Model(array('third' => 'baz', 'password' => 'hidden'));
     $model->relationships['one'] = new Model(array('foo' => 'bar', 'password' => 'hidden'));
     $model->relationships['many'] = array($first, $second, $third);
     $model->relationships['hidden'] = new Model(array('should' => 'not_visible'));
     $model->relationships['null'] = null;
     $this->assertEquals(array('name' => 'Taylor', 'age' => 25, 'null' => null, 'one' => array('foo' => 'bar'), 'many' => array(array('first' => 'foo'), array('second' => 'bar'), array('third' => 'baz')), 'null' => null), $model->to_array());
 }
Example #2
0
 /**
  * Update a record in the database
  *
  * @param $object Model object representing data to update
  */
 protected function update(Model $object)
 {
     $data = $this->escape_assoc($object->to_array());
     $query = "update {$this->table_name()} set ";
     $fields = $this->table_fields();
     foreach ($fields as $field) {
         $query .= "{$field} = '{$data[$field]}', ";
     }
     //remove the last pesky comma
     $query = chop($query);
     $query = substr($query, 0, strlen($query) - 1);
     $query .= " where id='{$data['id']}' limit 1";
     $this->query($query);
     return $object;
 }