示例#1
0
 protected function prepare(Type $type)
 {
     if (!$this->getConnection()->tableExists($this->table)) {
         throw new Exception("Table {$this->table} does not exist");
     }
     $name = $this->table;
     if ($this->tablePrefix && Text::startsWith($name, $this->tablePrefix)) {
         $name = substr($name, strlen($this->tablePrefix));
         $name = trim($name, '_');
     }
     if (empty($name)) {
         throw new Exception("Cannot infer model name from '{$this->table}'");
     }
     $name = Inflect::singularize($name);
     $model_name = Text::camelize($name);
     $vars['type'] = $type;
     $vars['namespace'] = $this->namespace;
     $vars['model_name'] = $model_name;
     $vars['table_name'] = $this->table;
     $vars['connection'] = $this->connectionService;
     $vars['name'] = str_replace('_', ' ', ucfirst($name));
     $vars['url'] = '/' . str_replace('_', '-', $name);
     $vars['primary_key'] = $this->primaryKey;
     return $vars;
 }
示例#2
0
 public function testSingularize()
 {
     $this->assertEquals(Inflect::singularize('customers'), 'customer');
 }