本文整理汇总了PHP中static::getTable方法的典型用法代码示例。如果您正苦于以下问题:PHP static::getTable方法的具体用法?PHP static::getTable怎么用?PHP static::getTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::getTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeQuery
protected static function executeQuery($command, array $attributes)
{
if (!count($attributes)) {
return true;
}
$model = new static();
if ($model->fireModelEvent('saving') === false) {
return false;
}
$attributes = collect($attributes);
$first = $attributes->first();
if (!is_array($first)) {
$attributes = collect([$attributes->toArray()]);
}
$keys = collect($attributes->first())->keys()->transform(function ($key) {
return "`" . $key . "`";
});
$bindings = [];
$query = $command . " into " . $model->getTable() . " (" . $keys->implode(",") . ") values ";
$inserts = [];
foreach ($attributes as $data) {
$qs = [];
foreach ($data as $value) {
$qs[] = '?';
$bindings[] = $value;
}
$inserts[] = '(' . implode(",", $qs) . ')';
}
$query .= implode(",", $inserts);
\DB::connection($model->getConnectionName())->insert($query, $bindings);
$model->fireModelEvent('saved', false);
}
示例2: isColumnNullable
public static function isColumnNullable($column_name)
{
$instance = new static();
// create an instance of the model to be able to get the table name
$answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='" . $instance->getTable() . "' AND COLUMN_NAME='" . $column_name . "' AND table_schema='" . env('DB_DATABASE') . "'"))[0];
return $answer->IS_NULLABLE == 'YES' ? true : false;
}
示例3: allCached
public static function allCached()
{
$instance = new static();
$tableName = $instance->getTable();
$eloquent = \Cache::remember($tableName . '_all', static::$expireCache, function () use($tableName, $instance) {
return $instance->all();
});
return $eloquent;
}
示例4: updateCache
/**
* Update all given Eloquent Model items in cache.
*
* @access public
* @static
* @return bool
*/
public static function updateCache($name = null)
{
self::initialize($name);
$instance = new static();
if (!Schema::hasTable($instance->getTable())) {
return false;
}
Cache::forever(self::$cacheName, static::all());
return true;
}
示例5: newInstanceWithOldInput
/**
* Lets us get a new instance populated with old input
* if there is any input
*
* @return EloquentModel
*/
public function newInstanceWithOldInput()
{
$instance = new static();
foreach (\Input::old() as $key => $value) {
if (\Schema::hasColumn($instance->getTable(), $key)) {
$instance->{$key} = $value;
}
}
return $instance;
}
示例6: getEnumValues
/**
* Get enum values from a column.
*
* @param string $column
*
* @return array
*/
public static function getEnumValues($column)
{
$instance = new static();
$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $instance->getTable() . ' WHERE Field = "' . $column . '"'))[0]->Type;
preg_match('/^enum\\((.*)\\)$/', $type, $matches);
$enum = [];
foreach (explode(',', $matches[1]) as $value) {
$v = trim($value, "'");
$enum = array_add($enum, $v, $v);
}
return $enum;
}
示例7: possibleEnumValues
public static function possibleEnumValues($name)
{
$instance = new static();
$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $instance->getTable() . ' WHERE Field = "' . $name . '"'))[0]->Type;
preg_match('/^enum\\((.*)\\)$/', $type, $matches);
$enum = array();
foreach (explode(',', $matches[1]) as $value) {
$v = trim($value, "'");
$enum[] = $v;
}
return $enum;
}
示例8: getEnumFromField
public static function getEnumFromField($name)
{
$instance = new static();
// create an instance of the model to be able to get the table name
$type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $instance->getTable() . ' WHERE Field = "' . $name . '"'))[0]->Type;
preg_match('/^enum\\((.*)\\)$/', $type, $matches);
$enum = array();
foreach (explode(',', $matches[1]) as $value) {
$v = trim($value, "'");
$enum[] = $v;
}
return $enum;
}
示例9: getSearchFields
/**
* Get all searchable fields
*
* @return array
*/
public static function getSearchFields()
{
$model = new static();
$fields = $model->search;
if (empty($fields)) {
$fields = Schema::getColumnListing($model->getTable());
$others[] = $model->primaryKey;
$others[] = $model->getUpdatedAtColumn() ?: 'created_at';
$others[] = $model->getCreatedAtColumn() ?: 'updated_at';
$others[] = method_exists($model, 'getDeletedAtColumn') ? $model->getDeletedAtColumn() : 'deleted_at';
$fields = array_diff($fields, $model->getHidden(), $others);
}
return $fields;
}
示例10: scopeMostVoted
public function scopeMostVoted($query)
{
// not working
//return $query->with(['voteCounter' => function($q){
// return $q->orderBy('up', 'DESC');
//}]);
$relatedClass = new static();
$class = $relatedClass->getMorphClass();
$table = $relatedClass->getTable();
$primary = $relatedClass->getKeyName();
$query->selectRaw("{$table}.*, voteable_id, voteable_type, IFNULL(up, 0), IFNULL(down, 0), IFNULL(up, 0) - IFNULL(down, 0) as total")->leftJoin('voteable_counter', 'voteable_counter.voteable_id', '=', "{$table}.{$primary}")->where(function ($queryWhere) use($class) {
return $queryWhere->where('voteable_type', '=', $class)->orWhere('voteable_type', '=', null);
})->orderBy('total', 'DESC')->orderBy('up', 'DESC');
}
示例11: schema
/**
* Return array of schema data for this model
*
* @return array
*/
public static function schema()
{
$model = new static();
$table = $model->getTable();
$schema = \DB::getDoctrineSchemaManager($table);
$columns = $schema->listTableColumns($table);
$fields = array();
foreach ($columns as $column) {
$name = $column->getName();
$type = $column->getType()->getName();
$length = $column->getLength();
$default = $column->getDefault();
$fields[] = compact('name', 'type', 'length', 'default');
}
return $fields;
}
示例12: logIn
/**
* Método para verificar el logueo de un usuario.
*
* Si es logueo es satisfactorio retorna un arreglo con los datos del usuario.
*
* @param array $credentials Contiene los datos del usuario (user, password)
* @param string $fieldId Contiene el campo de la tabla que representa el id.
* @param string $fieldUser Contiene el campo de la tabla que representa el usuario.
* @param string $fieldPass Contiene el campo de la tabla que representa el password.
* @param string $type Contiene el tipo de usuario.
*
* @throws RestException Si $credentials no es un array.
* @throws RestException Si falta algún argumento.
* @throws RestException Si los argumentos son cadenas vacias.
*
* return array
*
*/
public static function logIn($credentials, $fieldId, $fieldUser, $fieldPass, $type)
{
if (!is_array($credentials)) {
throw new RestException(__FILE__, "logIn: credentials debe ser un array.", 500);
}
if (!isset($credentials['user']) or !isset($credentials['password'])) {
throw new RestException(__FILE__, "logIn: faltan argumentos en las credenciales.", 400, ['message' => 'Faltan argumentos en las credenciales.']);
}
if ($credentials['user'] == "" or $credentials['password'] == "") {
throw new RestException(__FILE__, "logIn: los argumentos no pueden estar vacios.", 400, ['message' => 'Los argumentos no pueden estar vacios.']);
}
$obj = new static();
$results = $obj->select([$fieldId, $fieldUser, $fieldPass])->where([$fieldUser => $credentials['user'], $fieldPass => md5($credentials['password'])])->get();
if ($results->count() != 1) {
return false;
}
$data = ["data" => $results->first()->toArray(), "table" => $obj->getTable(), "type" => $type];
return $data;
}
示例13: getByFileable
/**
* Get the files for fileable
*
* @param string $fileableId fileable identifier
* @return Collection|static[]
*/
public static function getByFileable($fileableId)
{
$model = new static();
return $model->newQuery()->rightJoin($model->getFileableTable(), $model->getTable() . '.id', '=', $model->getFileableTable() . '.fileId')->where('fileableId', $fileableId)->select([$model->getTable() . '.*'])->get();
}
示例14: tableName
public static function tableName()
{
$ins = new static();
return $ins->getTable();
}
示例15: resolveConfiguration
/**
* kick start to just fetch the config
* @return array
*/
public static function resolveConfiguration()
{
static::$init = true;
$self = new static();
static::$init = false;
$conf = array('table' => $self->getTable(), 'fieldConf' => $self->getFieldConfiguration(), 'db' => $self->db, 'fluid' => $self->fluid, 'primary' => $self->primary);
unset($self);
return $conf;
}