本文整理汇总了PHP中Illuminate\Support\Facades\Schema::hasColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::hasColumn方法的具体用法?PHP Schema::hasColumn怎么用?PHP Schema::hasColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Schema
的用法示例。
在下文中一共展示了Schema::hasColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoUpdate
public function autoUpdate($save = false)
{
$this->getValue();
if ($this->action == "update" || $this->action == "insert") {
if (Input::hasFile($this->name)) {
$this->file = Input::file($this->name);
$filename = $this->filename != '' ? $this->filename : $this->file->getClientOriginalName();
$uploaded = $this->file->move($this->path, $filename);
if ($uploaded && is_object($this->model) && isset($this->db_name)) {
if (!Schema::hasColumn($this->model->getTable(), $this->db_name)) {
return true;
}
$this->new_value = $filename;
if (isset($this->new_value)) {
$this->model->setAttribute($this->db_name, $this->new_value);
} else {
$this->model->setAttribute($this->db_name, $this->value);
}
if ($save) {
return $this->model->save();
}
}
}
}
return true;
}
示例2: columnExists
/**
* @param $column
* @return bool
*/
private function columnExists($column)
{
if (!isset($this->sortable)) {
return Schema::hasColumn($this->getTable(), $column);
} else {
return in_array($column, $this->sortable);
}
}
示例3: all
public function all()
{
$query = $this->model;
if (Schema::hasColumn(str_plural($this->modelName), 'published_at')) {
$query = $query->where('is_published', 1)->where('published_at', '<=', Carbon::now()->format('Y-m-d h:i:s'));
}
return $query->orderBy('created_at', 'desc')->paginate(Config::get('quarx.pagination', 25));
}
示例4: down
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (!Schema::hasColumn('short_term_trainings', 'competency_id')) {
Schema::table('short_term_trainings', function (Blueprint $table) {
$table->dropColumn('competency_id');
});
}
}
开发者ID:rdg577,项目名称:laravel-mis,代码行数:13,代码来源:2016_05_16_084849_add_field_competency_id_to_short_term_training_table.php
示例5: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('videos', function (Blueprint $table) {
if (Schema::hasColumn('videos', 'config')) {
$table->dropColumn('config');
}
});
}
示例6: renameColumn
public static function renameColumn($tableName, $oldColumnName, $newColumnName, $type, $length, $unsigned, $nullable, $default = null)
{
if (Schema::hasColumn($tableName, $oldColumnName)) {
Schema::table($tableName, function (Blueprint $table) use($tableName, $oldColumnName, $newColumnName, $type, $length, $unsigned, $nullable, $default) {
$sql = DBLibrary::getAlterTableSql($tableName, $oldColumnName, $newColumnName, $type, $length, $unsigned, $nullable, $default);
DB::select(DB::raw($sql));
});
}
}
示例7: entryRelationDisplayColumn
protected function entryRelationDisplayColumn()
{
$relation_display_column = $this->commandObj->ask('Please input column name shown in index page.(If you want to cancel, enter "cancel")');
if ($relation_display_column == 'cancel') {
$this->commandObj->info('make:relation canceled!');
exit;
} else {
if (!Schema::hasColumn($this->model_A_tablename, $relation_display_column)) {
$this->commandObj->error('Column "' . $relation_display_column . '" is not exist in ' . $this->model_A_tablename . ' tables');
$this->entryRelationDisplayColumn();
} else {
return $relation_display_column;
}
}
}
示例8: _exec_table_builder
private function _exec_table_builder($table_name, $fields_to_add)
{
$table_name = $this->assoc_table_name($table_name);
if (!Schema::hasTable($table_name)) {
Schema::create($table_name, function ($table) {
$table->increments('id');
});
}
if (is_array($fields_to_add)) {
Schema::table($table_name, function ($schema) use($fields_to_add, $table_name) {
foreach ($fields_to_add as $name => $meta) {
$is_index = substr($name, 0, 1) === '$';
$is_default = null;
$is_nullable = true;
if (!$is_index) {
if (is_array($meta)) {
if (!isset($meta['type'])) {
$name = array_shift($meta);
$type = array_shift($meta);
} else {
$type = $meta['type'];
}
if (isset($meta['default'])) {
$is_default = $meta['default'];
if ($is_default == 'not_null') {
$is_nullable = false;
}
}
} else {
$type = $meta;
}
if (!Schema::hasColumn($table_name, $name)) {
$fluent = $schema->{$type}($name);
if ($is_default !== null) {
$fluent->default($is_default)->nullable();
}
if ($is_nullable) {
$fluent->nullable();
}
}
}
}
});
}
}
示例9: matchColumns
/**
* Match columns in the database
*/
public function matchColumns()
{
Schema::table($this->name, function ($table) {
$table->engine = 'InnoDB';
// Loop through all table columns and check if they exists in the database already.
// If one of them doesn't exists then create it
foreach ($this->columns as $column => $generator) {
// If column doesn't exist then create it
if (!Schema::hasColumn($this->getName(), $column)) {
call_user_func($generator, $table);
}
}
foreach ($this->getTableColumns() as $dbColumn) {
if (!isset($this->columns[$dbColumn->Field])) {
$table->dropColumn($dbColumn->Field);
}
}
});
}
示例10: compose
public function compose($view)
{
$defaultLanguage = Cache::get('default_language');
$viewName = $view->getName();
$pos = strrpos($viewName, '.');
$name = substr($viewName, $pos + 1);
if (preg_match('/^submenu_/i', $name)) {
$target = preg_split('/^submenu_/i', $name);
$table = 'layout_' . $target[1];
if (Schema::hasTable($table)) {
$db = new Content($table);
if (Schema::hasColumn($table, 'order')) {
$items = $db->language($defaultLanguage->id)->active()->orderBy('order')->get();
} elseif (Schema::hasColumn($table, 'published_date')) {
$items = $db->language($defaultLanguage->id)->active()->orderBy('published_date', 'desc')->get();
}
$view->with(compact('items'));
}
}
if ($name == 'menu') {
$table = 'menus';
if (Schema::hasTable($table)) {
$db = new Content($table);
$result = $db->language($defaultLanguage->id)->active()->orderBy('order')->get();
$groupId = $db->whereType('group')->whereDisplay('Subjects')->first();
$menuItems = $result->filter(function ($item) {
return $item->group_id == 1;
});
$view->with(compact('menuItems'));
}
} else {
$table = 'partial_' . $name;
if (Schema::hasTable($table)) {
$db = new Content($table);
$content = $db->language($defaultLanguage->id)->active()->first();
$view->with($table, $content);
}
}
$view;
}
示例11: createTree
public function createTree($model = false, $act = false)
{
$this->tree = array();
$query = $act ? self::where('act', 1) : self::newQuery();
if (Schema::hasColumn($this->table, 'path')) {
$list = $query->orderBy('parent', 'asc')->orderBy('sort', 'asc')->get();
} else {
$siteClass = config('model.site') ?: 'Model\\Site';
$siteTable = (new $siteClass())->getTable();
$query->select($this->table . '.*', "{$siteTable}.path");
$list = $query->leftJoin($siteTable, "{$this->table}.site_id", '=', "{$siteTable}.id")->orderBy("{$this->table}.parent", 'asc')->orderBy("{$this->table}.sort", 'asc')->get();
}
foreach ($list as $item) {
$this->listTree[$item->id] = $item;
$this->parentTree[$item->parent][] = $item->id;
}
if (!empty($this->parentTree[0]) && is_array($this->parentTree[0])) {
foreach ($this->parentTree[0] as $k => $item) {
$this->_branch($item, $this->tree[$k], $model);
}
}
return $this->tree;
}
示例12: prepareSelectValues
protected function prepareSelectValues()
{
$this->db->select($this->getOptionDB('table') . '.id');
$def = $this->controller->getDefinition();
if (isset($def['options']['is_sortable']) && $def['options']['is_sortable']) {
if (!Schema::hasColumn($this->getOptionDB('table'), "priority")) {
Schema::table($this->getOptionDB('table'), function ($table) {
$table->integer("priority");
});
}
$this->db->addSelect($this->getOptionDB('table') . '.priority');
}
$fields = $this->controller->getFields();
foreach ($fields as $name => $field) {
$field->onSelectValue($this->db);
}
}
示例13: doCreateField
protected function doCreateField($table_name, $field_name)
{
$field_bd = $this->getAttribute('field');
$data = Session::all();
if (!Session::has($table_name . '.' . $field_name)) {
if ($field_bd && !Schema::hasColumn($table_name, $field_name)) {
Session::push($table_name . '.' . $field_name, 'created');
@(list($field, $param) = explode("|", $field_bd));
Schema::table($table_name, function ($table) use($field_name, $field, $param) {
$field_add = $table->{$field}($field_name);
if ($param) {
$field_add->length($param);
}
});
} else {
Session::push($table_name . '.' . $field_name, 'created');
}
}
}
示例14: columnExists
/**
* @param $model
* @param $column
*
* @return bool
*/
private function columnExists($model, $column)
{
return isset($model->sortable) ? in_array($column, $model->sortable) : Schema::hasColumn($model->getTable(), $column);
}
示例15: dropColumn
/**
* Drop a column from a table.
*
* @param $tableName
* @param $column
*/
public function dropColumn($tableName, $column)
{
// Check for its existence before dropping
if (Schema::hasColumn($tableName, $column)) {
Schema::table($tableName, function (Blueprint $table) use($column) {
$table->dropColumn($column);
});
}
}