Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
evsmash/articles / libs / Schemas / ArticlesCategories.php
Size: Mime:
<?php 

namespace Evsmash\Articles\Schemas;

use Evsmash\Core\Schemas\Base;

use Evsmash\Articles\ArticlesCategory;
use Evsmash\Settings\TranslationConfig as Translation;

class ArticlesCategories extends Base {

	protected $table = 'articles_categories';

	// validate
	static public function validate() {

		return [
			'name' => 'req|max:100', 
			'description' => 'max:10000',
			'published' => 'int',
			'type_id' => 'int', 
		];

	}

	// translation
	static public function translation() {

		$config = new Translation;
		$config->set('name');
		return $config;

	}

	// create
	public function create() {

		$this->schemaCreate(function($m) {
			$m->increments('id');
			$m->string('name', 100);
			$m->tinyInteger('published');
			$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(ArticlesCategory::where('depth', 0)->first())) {
			$item = new ArticlesCategory;
			$item->name = 'root';
			$item->save();
		}

	}

	// rebuild_1
	public function rebuild_1() {

		$this->schemaAdd('description', function($m) {
			$m->text('description')->after('name');
		});

	}

}