当前位置: 首页>>代码示例>>PHP>>正文


PHP Schema::hasColumn方法代码示例

本文整理汇总了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;
 }
开发者ID:parabol,项目名称:laravel-cms,代码行数:26,代码来源:File.php

示例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);
     }
 }
开发者ID:svadim-21,项目名称:column-sortable,代码行数:12,代码来源:Sortable.php

示例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));
 }
开发者ID:YABhq,项目名称:Quarx,代码行数:8,代码来源:ApiController.php

示例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');
         }
     });
 }
开发者ID:despark,项目名称:ignicms,代码行数:13,代码来源:2016_10_27_081519_videos_remove_config_column.php

示例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));
         });
     }
 }
开发者ID:syscover,项目名称:pulsar,代码行数:9,代码来源:DBLibrary.php

示例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;
         }
     }
 }
开发者ID:dog-ears,项目名称:crud-d-scaffold,代码行数:15,代码来源:MakeRelation.php

示例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();
                         }
                     }
                 }
             }
         });
     }
 }
开发者ID:hyrmedia,项目名称:microweber,代码行数:45,代码来源:Database.php

示例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);
             }
         }
     });
 }
开发者ID:lifeentity,项目名称:dbsynchronize,代码行数:22,代码来源:Table.php

示例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;
 }
开发者ID:xavierauana,项目名称:events,代码行数:40,代码来源:FrontPartialsComposer.php

示例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;
 }
开发者ID:ognestraz,项目名称:laravel-model,代码行数:23,代码来源:Tree.php

示例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);
     }
 }
开发者ID:arturishe21,项目名称:buider,代码行数:17,代码来源:QueryHandler.php

示例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');
         }
     }
 }
开发者ID:arturishe21,项目名称:buider,代码行数:19,代码来源:AbstractField.php

示例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);
 }
开发者ID:kyslik,项目名称:column-sortable,代码行数:10,代码来源:Sortable.php

示例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);
         });
     }
 }
开发者ID:awatbayazidi,项目名称:foundation,代码行数:15,代码来源:Migration.php


注:本文中的Illuminate\Support\Facades\Schema::hasColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。