Repository URL to install this package:
|
Version:
3.2.0 ▾
|
<?php
namespace Evsmash\Files\Schemas;
use Evsmash\Core\Schemas\Base;
use Evsmash\Files\File;
class Files extends Base {
protected $table = 'files';
// validate
static public function validate() {
return [
'file' => 'max:200',
'name' => 'max:100',
'description' => 'max:200',
'type' => 'req|max:6',
'ext' => 'req|max:6',
'resolution' => 'max:16',
'directory_id' => 'int',
'downloads' => 'int'
];
}
// create
public function create() {
$this->schemaCreate(function($m) {
$m->increments('id');
$m->string('file', 200);
$m->string('name', 100);
$m->string('description', 200);
$m->string('type', 6);
$m->string('ext', 6);
$m->string('resolution', 16);
$m->tinyInteger('download');
$m->nullabletimestamps();
$m->softDeletes();
});
}
// rebuild 1
public function rebuild_1() {
$this->schemaDrop('download');
}
// rebuild 2
public function rebuild_2() {
$this->schemaAdd('directory_id', function($m) {
$m->integer('directory_id')->after('deleted_at');
});
}
// rebuild 3
public function rebuild_3() {
File::where('directory_id', 0)->update(['directory_id' => 1]);
}
// rebuild 4
public function rebuild_4() {
$this->schemaAdd('downloads', function($m) {
$m->integer('downloads')->after('directory_id');
});
}
}