本文整理汇总了PHP中Schema::getColumnListing方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::getColumnListing方法的具体用法?PHP Schema::getColumnListing怎么用?PHP Schema::getColumnListing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schema
的用法示例。
在下文中一共展示了Schema::getColumnListing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
public function import($entity)
{
$appHelper = new libs\AppHelper();
$className = $appHelper->getNameSpace() . $entity;
$model = new $className();
$table = $model->getTable();
$columns = \Schema::getColumnListing($table);
$key = $model->getKeyName();
$notNullColumnNames = array();
$notNullColumnsList = \DB::select(\DB::raw("SHOW COLUMNS FROM `" . $table . "` where `Null` = 'no'"));
if (!empty($notNullColumnsList)) {
foreach ($notNullColumnsList as $notNullColumn) {
$notNullColumnNames[] = $notNullColumn->Field;
}
}
$status = \Input::get('status');
$filePath = null;
if (\Input::hasFile('import_file') && \Input::file('import_file')->isValid()) {
$filePath = \Input::file('import_file')->getRealPath();
}
if ($filePath) {
\Excel::load($filePath, function ($reader) use($model, $columns, $key, $status, $notNullColumnNames) {
$this->importDataToDB($reader, $model, $columns, $key, $status, $notNullColumnNames);
});
}
$importMessage = $this->failed == true ? \Lang::get('panel::fields.importDataFailure') : \Lang::get('panel::fields.importDataSuccess');
return \Redirect::to('panel/' . $entity . '/all')->with('import_message', $importMessage);
}
示例2: test
public function test()
{
$columns = \Schema::getColumnListing('tp_goods');
// echo '<pre>'.print_r($columns,true).'</pre>';
$columns = implode("', '", $columns);
echo $columns;
}
示例3: boot
public static function boot()
{
self::creating(function ($custom_field) {
if (in_array($custom_field->db_column_name(), Schema::getColumnListing(DB::getTablePrefix() . CustomField::$table_name))) {
//field already exists when making a new custom field; fail.
return false;
}
return DB::statement("ALTER TABLE " . DB::getTablePrefix() . CustomField::$table_name . " ADD COLUMN (" . $custom_field->db_column_name() . " TEXT)");
});
self::updating(function ($custom_field) {
//print(" SAVING CALLBACK FIRING!!!!! ");
if ($custom_field->isDirty("name")) {
//print("DIRTINESS DETECTED!");
//$fields=array_keys($custom_field->getAttributes());
//;
//add timestamp fields, add id column
//array_push($fields,$custom_field->getKeyName());
/*if($custom_field::timestamps) {
}*/
//print("Fields are: ".print_r($fields,true));
if (in_array($custom_field->db_column_name(), Schema::getColumnListing(CustomField::$table_name))) {
//field already exists when renaming a custom field
return false;
}
return DB::statement("UPDATE " . CustomField::$table_name . " RENAME " . self::name_to_db_name($custom_field->get_original("name")) . " TO " . $custom_field->db_column_name());
}
return true;
});
self::deleting(function ($custom_field) {
return DB::statement("ALTER TABLE " . CustomField::$table_name . " DROP COLUMN " . $custom_field->db_column_name());
});
}
示例4: index
/**
* Display a listing of the resource.
* GET /pages
*
* @return Response
*/
public function index()
{
//set data & columns datatables
$data['exclude_columns'] = array("", "password", "remember_token", "created_at", "updated_at");
$data['json_columns'] = $this->array2Columns(Schema::getColumnListing('users'), $data['exclude_columns']);
$data['json_data'] = $this->result2datatables(User::all()->toArray());
return View::make(Config::get('srm.theme_directory') . 'users.index', $data);
}
示例5: hasColumn
/**
* Check if model's table has column
*
* @param \Eloquent $model
* @param string $column
* @return bool
*/
public static function hasColumn($model, $column)
{
$table = $model->getTable();
$columns = \Cache::remember('amigridview.columns.' . $table, 60, function () use($table) {
return \Schema::getColumnListing($table);
});
return array_search($column, $columns) !== false;
}
示例6: writeExcel
public function writeExcel()
{
dd(\Schema::getColumnListing());
Excel::create('Filename', function ($excel) {
$excel->sheet('Sheetname', function ($sheet) {
// Sheet manipulation
});
})->store('xlsx', storage_path('excel'));
}
示例7: export
public static function export($table, $dbConnection = 'default')
{
$data = DB::connection($dbConnection)->table($table)->get();
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
$csv->insertOne(\Schema::getColumnListing($table));
foreach ($data as $row) {
$csv->insertOne((array) $row);
}
$csv->output($table . '-' . date('YmdHi') . '.csv');
}
示例8: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$people = bbStock::all();
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
$csv->insertOne(\Schema::getColumnListing('bbstock'));
foreach ($people as $person) {
$csv->insertOne($person->toArray());
}
$csv->output('bbstock.csv');
}
示例9: getData
public function getData()
{
$draw = Input::get('draw');
if (Input::get('order') && Input::get('columns')) {
$columns = Input::get('columns');
$sort_cri = Input::get('order');
if ($sort_cri[0]) {
$sort_field = $columns[$sort_cri[0]['column']]['data'];
$sort_order = $sort_cri[0]['dir'];
}
}
$length = Input::get('length');
$start = Input::get('start');
$search_fields_or_search_text = Input::get('searchFields');
if (isset($limitFrom) && isset($rec_per_page) && isset($search_fields_or_search_text)) {
if (is_array($search_fields_or_search_text)) {
$usertotal_search_query = User::query();
$userdata_search_query = User::query();
foreach ($search_fields_or_search_text as $search_field => $search_value) {
$totalUsers = $usertotal_search_query->where($search_field, 'LIKE', '%' . $search_value . '%');
$users = $userdata_search_query->where($search_field, 'LIKE', '%' . $search_value . '%');
}
$totalUsers = $usertotal_search_query->count();
$users = $userdata_search_query->skip($limitFrom)->take($rec_per_page)->get();
} else {
$user_fields = \Schema::getColumnListing('users');
$usertotal_search_query = User::query();
$userdata_search_query = User::query();
foreach ($user_fields as $user_field) {
$totalUsers = $usertotal_search_query->orWhere($user_field, 'LIKE', '%' . $search_fields_or_search_text . '%');
$users = $userdata_search_query->orWhere($user_field, 'LIKE', '%' . $search_fields_or_search_text . '%');
}
$totalUsers = $usertotal_search_query->count();
$users = $userdata_search_query->skip($limitFrom)->take($rec_per_page)->get();
}
} else {
if (isset($start) && isset($length) && isset($sort_field) && isset($sort_order)) {
$totalUsers = User::count();
$users = User::orderBy($sort_field, $sort_order)->skip($start)->take($length)->get();
} else {
if (isset($start) && isset($length)) {
$totalUsers = User::count();
$users = User::skip($start)->take($length)->get();
} else {
$totalUsers = User::count();
$users = User::all();
}
}
}
return ['draw' => (int) $draw, 'recordsFiltered' => $totalUsers, 'recordsTotal' => $totalUsers, 'data' => $users];
}
示例10: getData
public function getData()
{
$sort_field = Input::get('sortField');
$sort_order = Input::get('sortOrder');
$rec_per_page = Input::get('recPerPage');
$current_page = Input::get('currentPage');
$limitFrom = ($current_page - 1) * $rec_per_page;
$search_fields_or_search_text = Input::get('searchFields');
if (isset($limitFrom) && isset($rec_per_page) && isset($search_fields_or_search_text)) {
if (is_array($search_fields_or_search_text)) {
$usertotal_search_query = User::query();
$userdata_search_query = User::query();
foreach ($search_fields_or_search_text as $search_field => $search_value) {
$totalUsers = $usertotal_search_query->where($search_field, 'LIKE', '%' . $search_value . '%');
$users = $userdata_search_query->where($search_field, 'LIKE', '%' . $search_value . '%');
}
$totalUsers = $usertotal_search_query->count();
$users = $userdata_search_query->skip($limitFrom)->take($rec_per_page)->get();
} else {
$user_fields = \Schema::getColumnListing('users');
$usertotal_search_query = User::query();
$userdata_search_query = User::query();
foreach ($user_fields as $user_field) {
$totalUsers = $usertotal_search_query->orWhere($user_field, 'LIKE', '%' . $search_fields_or_search_text . '%');
$users = $userdata_search_query->orWhere($user_field, 'LIKE', '%' . $search_fields_or_search_text . '%');
}
$totalUsers = $usertotal_search_query->count();
$users = $userdata_search_query->skip($limitFrom)->take($rec_per_page)->get();
}
} else {
if (isset($limitFrom) && isset($rec_per_page) && isset($sort_field) && isset($sort_order)) {
$totalUsers = User::count();
$users = User::orderBy($sort_field, $sort_order)->skip($limitFrom)->take($rec_per_page)->get();
} else {
if (isset($limitFrom) && isset($rec_per_page)) {
$totalUsers = User::count();
$users = User::skip($limitFrom)->take($rec_per_page)->get();
} else {
$totalUsers = User::count();
$users = User::all();
}
}
}
return ['userCount' => $totalUsers, 'users' => $users];
}
示例11: search
public function search($input, $getResults = true)
{
$query = Discuss::query();
$columns = Schema::getColumnListing('discusses');
$attributes = array();
foreach ($columns as $attribute) {
if (isset($input[$attribute]) and !empty($input[$attribute])) {
$query->where($attribute, $input[$attribute]);
$attributes[$attribute] = $input[$attribute];
} else {
$attributes[$attribute] = null;
}
}
if ($getResults) {
return [$query->get(), $attributes];
} else {
return $query;
}
}
示例12: scopeJoinWithSelect
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $table join the table
* @param string $one joins first parameter
* @param string|array|null $operatorOrCollumns operator condition or collums list
* @param string $two joins two parameter
* @param string $type join type (left, right, '', etc)
* @param bool|false $where custom where condition
* @param array $collumns if you will not pass collumns, it will retreive the collumn listing. If you pass null
* it will not get any data from the model.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeJoinWithSelect($query, $table, $one, $operatorOrCollumns, $two, $type = "left", $where = false, $collumns = array())
{
// if the operator collumns are in
if (is_array($operatorOrCollumns) || is_null($operatorOrCollumns)) {
$collumns = $operatorOrCollumns;
$operatorOrCollumns = "=";
}
if (!is_null($collumns)) {
// if there is no specific collumns, lets get all
if (empty($collumns)) {
$collumns = \Schema::getColumnListing($table);
}
// build the table values prefixed by the table to ensure unique values
foreach ($collumns as $related_column) {
$query->addSelect(new Expression("`{$table}`.`{$related_column}` AS `{$table}.{$related_column}`"));
}
}
return $query->join($table, $one, $operatorOrCollumns, $two, $type, $where);
}
示例13: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$userClass = config('auth.model');
if (!$userClass) {
$userClass = config('auth.providers.users.model');
}
$list = \Schema::getColumnListing('users');
$list2 = array_filter($list, function ($e) {
return $e != 'id' && !str_contains($e, 'password');
});
$user = new $userClass();
$passWord = $this->secret('Password');
$user->password = Hash::make($passWord);
foreach ($list2 as $option) {
if ($this->option($option)) {
$user->{$option} = $this->option($option);
}
}
$user->save();
$this->comment($user->id);
}
示例14: settings
public function settings($table)
{
if (!Schema::hasTable($table)) {
$this->data['result'] = 0;
$this->data['message'] = 'Specified table not found';
} else {
$this->data['result'] = 1;
$this->data['message'] = '';
$this->data['table_name'] = $table;
$users_columns = Schema::getColumnListing($table);
if (DB::table("crud_table_rows")->where('table_name', $table)->count() <= 0) {
foreach ($users_columns as $column) {
DB::table('crud_table_rows')->insert(['table_name' => $table, 'column_name' => $column, 'type' => 'text', 'create_rule' => '', 'edit_rule' => '', 'creatable' => true, 'editable' => true, 'listable' => true, 'created_at' => Utils::timestamp(), 'updated_at' => Utils::timestamp()]);
}
}
$columns = DB::table("crud_table_rows")->where('table_name', $table)->get();
foreach ($columns as $column) {
if ($column->type == "radio") {
$radios = DB::table("crud_table_pairs")->where("crud_table_id", $column->id)->get();
$column->radios = $radios;
}
if ($column->type == "checkbox") {
$checkboxes = DB::table("crud_table_pairs")->where("crud_table_id", $column->id)->get();
$column->checkboxes = $checkboxes;
}
if ($column->type == "range") {
$range = DB::table("crud_table_pairs")->where("crud_table_id", $column->id)->first();
$column->range_from = $range->key;
$column->range_to = $range->value;
}
if ($column->type == "select") {
$selects = DB::table("crud_table_pairs")->where("crud_table_id", $column->id)->get();
$column->selects = $selects;
}
}
$this->data['columns'] = $columns;
$this->data['table'] = $this->table;
}
return View::make('tables.settings', $this->data);
}
示例15: export_data_excel
public function export_data_excel(Request $request)
{
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="GiftProjectDump_' . date("YmdHis") . '.xlsx"');
header('Cache-Control: max-age=0');
$excel = new PHPExcel();
$add = function (&$array, $table, $row, $key) {
if ($key == 'password') {
return;
}
$array[] = $row->getAttributeValue($key);
};
foreach (['App\\Household', 'App\\HouseholdAddress', 'App\\Child', 'App\\HouseholdPhone', 'App\\User'] as $model) {
$table = (new $model())->getTable();
$sheet = new PHPExcel_Worksheet($excel, $table);
$columns = \Schema::getColumnListing($table);
$sheet->fromArray($columns, NULL, 'A1');
$i = 2;
foreach ($model::all() as $row) {
$array = array();
foreach ($columns as $key) {
$add($array, $table, $row, $key);
}
$sheet->fromArray($array, NULL, 'A' . $i++);
}
Export::AutoSizeSheet($sheet);
$excel->addSheet($sheet);
}
$excel->removeSheetByIndex(0);
$writer = new PHPExcel_Writer_Excel2007($excel);
$writer->setOffice2003Compatibility(true);
$writer->save('php://output');
// TODO: How else can I tell Laravel to let me write the response?
flush();
exit(0);
}