Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($classname = $this->argument('name')) {
         $classname = ucfirst($classname);
         $template = $this->getTemplateDir() . $this->templateName;
         if (file_exists($template)) {
             if (file_exists(ModelCore::getModelDirectory())) {
                 $text = str_replace($this->mergeCode, $classname, file_get_contents($template));
                 $tableDefine = $this->option('table') ? 'protected $table = \'' . $this->option('table') . '\';' : '';
                 $text = str_replace('{table-define}', $tableDefine, $text);
                 $path = ModelCore::getModelDirectory() . $classname . $this->suffix . $this->ext;
                 if (!file_exists($path)) {
                     if (false == file_put_contents($path, $text)) {
                         $this->error('Can\'t write file to ' . ControllerCore::getControllerDirectory() . $path);
                     } else {
                         chmod($path, 0766);
                         $this->info($classname . ' Model class created.');
                     }
                 } else {
                     $this->error($classname . ' already exist');
                 }
             } else {
                 $this->error('Model class directory not found ' . ControllerCore::getControllerDirectory());
             }
         } else {
             $this->error('Model class template not found ' . $template);
         }
     }
 }
Beispiel #2
0
 /**
  * Overrides parent magic get to create a custom attribute
  *
  * @return string
  */
 public function __get($key)
 {
     switch ($key) {
         case 'fullname':
             return $this->attributes['firstname'] . ' ' . $this->attributes['lastname'];
         case 'gender_value':
             if ($this->gender == 1) {
                 return 'Male';
             } elseif ($this->gender == 2) {
                 return 'Female';
             } else {
                 return '';
             }
     }
     return parent::__get($key);
 }
Beispiel #3
0
 /**
  * Gets the public url for the file
  * @param ModelCore The subject model
  * @param string $column The column name
  * @return string
  */
 public function getPublicUrl(ModelCore $model = NULL, $column = '')
 {
     $url = '';
     $filename = '';
     if ($model) {
         $filename = $model->getAttributes()[$column];
         $this->column = $column;
     } elseif ($this->subjectModel) {
         $filename = $this->subjectModel->{$this->column};
     }
     if (!$filename) {
         return $url;
     }
     $configPath = $this->getConfigPath($model);
     $url = request()->root() . '/images/' . $configPath . '/' . $filename;
     return $url;
 }