Repository URL to install this package:
|
Version:
3.2.0 ▾
|
<?php
namespace Evsmash\Files\Schemas;
use Evsmash\Core\Schemas\Base;
use Evsmash\Files\FilesDirectory;
class FilesDirectories extends Base {
protected $table = 'files_directories';
// validate
static public function validate() {
return [
'name' => 'req|max:100',
];
}
// create
public function create() {
$this->schemaCreate(function($m) {
$m->increments('id');
$m->string('name', 100);
$m->nullabletimestamps();
$m->softDeletes();
$m->integer('parent_id')->nullable();
$m->integer('lft')->nullable();
$m->integer('rgt')->nullable();
$m->integer('depth')->nullable();
});
}
// root
public function root() {
if(is_null(FilesDirectory::where('depth', 0)->first())) {
$item = new FilesDirectory;
$item->name = 'root';
$item->save();
}
}
}