public static function createFolder(array $attributes = []) { $dir = new static(); $dir->is_dir = 1; $dir->user_id = isset($attributes['user_id']) ? $attributes['user_id'] : 0; $dir->project_id = isset($attributes['project_id']) ? $attributes['project_id'] : 0; $dir->parent_id = isset($attributes['parent_id']) ? $attributes['parent_id'] : 0; $dir->name = isset($attributes['name']) ? $attributes['name'] : '新建文件夹'; $dir->type = isset($attributes['type']) ? $attributes['type'] : 'dir'; $dir->path = isset($attributes['path']) ? $attributes['path'] : '/'; $dir->save(); $status = true; if (isset($attributes['path']) || $dir->parent_id == 0) { $dir->path .= $dir->id . '/'; } else { $path = $dir->parent()->where('project_id', $dir->project_id)->where('is_dir', 1)->pluck('path'); if (!$path || $path->count() == 0) { $dir->delete(); $status = false; } else { if (!is_string($path)) { $path = $path[0]; } $dir->path = $path . $dir->id . '/'; } } if ($status) { $dir->save(); return static::find($dir->id); } }
public static function setContext($locale, $parent) { static::$locale = $locale; static::$parent = $parent; }