예제 #1
0
 /**
  * Make source file ..
  *
  * @param Command $command
  * @throws SeederException
  * @return bool|mixed
  */
 public function create(Command $command)
 {
     $path = self::getConfig('path');
     if (!File::isWritable($path)) {
         throw new SeederException('Path are not writable. Please chmod!');
     }
     $source = explode(',', self::getSource());
     array_walk($source, function ($name) use($path, $command) {
         $model = 'App\\' . ucfirst(strtolower($name));
         if (!isEloquentExists($model)) {
             $command->error(sprintf('Model %s not exists. Skipped!', $model));
             return false;
         }
         $fullPath = getFullPathSource($name, $this);
         if (File::exists($fullPath)) {
             $command->error(sprintf('Model %s already exists. Skipped!', $name));
             return false;
         }
         File::put($fullPath, arrayToYaml(['class' => ucfirst($name), 'source' => arrayToYaml(getTableSchema($model), 1)], 1));
         $command->info(sprintf('File %s created successfully!', $name));
     });
 }
예제 #2
0
 function getDiffFiles(array $files, \Illuminate\Support\Collection $seeded, \LaravelSeed\Contracts\ProviderInterface $provider)
 {
     $edited = [];
     array_map(function ($seed) use($files, &$edited, $provider) {
         $fullPath = getFullPathSource($seed->name, $provider);
         if (!in_array($fullPath, $files)) {
             return false;
         }
         $key = array_search($fullPath, $files);
         $filemtime = filemtime($files[$key]);
         if ($filemtime > $seed->hash) {
             $edited[] = $fullPath;
         }
         return false;
     }, $seeded->toArray());
     $diff = [];
     array_walk($files, function ($file) use($seeded, &$diff) {
         $filename = pathinfo($file)['filename'];
         if (!$seeded->contains('name', $filename)) {
             $diff[] = $file;
         }
     });
     return array_merge($diff, $edited);
 }