本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getFillable方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getFillable方法的具体用法?PHP Model::getFillable怎么用?PHP Model::getFillable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::getFillable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Create a new model instance and store it in the database
*
* @param array $data
* @return static
*/
public function store(array $data)
{
// Remove non-fillable items from our data array
foreach ($data as $key => $value) {
if (!in_array($key, $this->model->getFillable())) {
unset($data[$key]);
}
}
// Do we need to create a reference id?
$referenceColumn = $this->referenceIdColumnName();
if ($this->model->isFillable($referenceColumn) && !isset($data[$referenceColumn])) {
$data[$referenceColumn] = $this->generateReferenceId();
}
// Return the new model object
return $this->model->create($data);
}
示例2: apply
public function apply(Model $model, RepositoryContract $repository)
{
$fields = $this->fields;
$query = $this->query;
if (!$fields) {
$fields = $model->getFillable();
}
switch ($this->type) {
case self::$ST_USE_AT_BEGIN:
$query = '%' . $this->query;
break;
case self::$ST_USE_AT_END:
$query = $this->query . '%';
break;
case self::$ST_USE_AT_BOTH:
$query = '%' . $this->query . '%';
break;
}
$query = $model->where(function ($q) use($fields, $query) {
foreach ($fields as $i => $field) {
if ($i == 0) {
$q->where($field, 'like', $query);
}
$q->orWhere($field, 'like', $query);
}
});
return $query;
}
示例3: processFilters
private function processFilters($query, $filters)
{
$allowed_filters = array_merge($this->model->getFillable(), $this->model->getGuarded());
if (count($filters)) {
foreach ($filters as $filter) {
if (!in_array($filter['name'], $allowed_filters)) {
throw new InvalidArgumentException("The field [" . $filter['name'] . "] is not a valid filterable field.");
}
if (isset($filter['operator'])) {
switch (strtolower($filter['operator'])) {
case 'in':
$query->whereIn($filter['name'], $filter['value']);
break;
case 'like':
$query->where($filter['name'], 'LIKE', $filter['value']);
break;
case 'not null':
$query->whereNotNull($filter['name']);
break;
case 'null':
$query->whereNull($filter['name']);
break;
default:
$query->where($filter['name'], $filter['value']);
break;
}
} else {
$query->where($filter['name'], $filter['value']);
}
}
}
return $query;
}
示例4: inlineUpdate
public function inlineUpdate($id)
{
$this->instance = $this->find($id);
if (empty($this->instance)) {
return false;
}
$data = $this->request->all();
$updated = false;
if (method_exists($this->instance, 'getRepository')) {
$repository = $this->instance->getRepository();
if (method_exists($repository, 'inlineSave')) {
if ($repository->inlineSave($data)) {
$updated = true;
} else {
return false;
}
}
}
if ($updated == false) {
$fillableFields = $this->instance->getFillable();
foreach ($data as $key => $value) {
if (in_array($key, $fillableFields)) {
$this->instance->{$key} = $value;
}
}
if ($this->instance->update()) {
$updated = true;
}
}
return $updated;
}
示例5: getFillable
/**
* Look for admin model config, if there is nothing fallback to Model property.
*
* @return array|mixed
*/
public function getFillable()
{
$fillable = $this->getOption('fillable', $this->model->getFillable());
if ($fillable == ['*']) {
$fillable = array_diff($this->columns, $this->getGuarded());
}
return $fillable;
}
示例6: attachData
/**
* Attach incoming data to the model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* Model to attach data to.
*/
public function attachData(Model $model)
{
$input = Input::all();
$fields = $model->getFillable();
foreach ($fields as $field) {
if (isset($input[$field])) {
$model->{$field} = $input[$field];
}
}
}
示例7: filterModelAttributes
public static function filterModelAttributes($array, Model $model)
{
$column = array();
foreach ($array as $attribute => $value) {
if (in_array($attribute, $model->getFillable())) {
$column[] = $attribute;
}
}
array_has($column, $model->getKeyName()) == false & count($column) > 0 ? $column[] = $model->getKeyName() : null;
return count($column) > 0 ? $column : array('*');
}
示例8: setDefaultColumns
/**
* Set default name columns to be displayed if avaliable in the current model.
*
* @param array $columns
* @return Datagrid
* @throws \Exception
*/
public function setDefaultColumns(array $columns)
{
$this->defaultColumns = $columns;
$fillable = $this->model->getFillable();
if (count($fillable) === 0) {
throw new \Exception('This model has no fillable columns defined.');
}
foreach ($columns as $column => $alias) {
if (in_array($column, $fillable)) {
$this->addColumns([$column => $alias]);
break;
}
}
return $this;
}
示例9: storeModel
/**
* Store a newly created resource in storage.
*
* @param \Garble\Http\Requests\TextsRequest $request
*
* @return \Illuminate\Http\Response
*/
public function storeModel(TextsRequest $request)
{
$modelAttributes = [];
foreach ($this->modelInstance->getFillable() as $key) {
$input = $request->input($key);
if (!empty($input)) {
$modelAttributes[$key] = $input;
}
}
$model = $this->modelInstance->create($modelAttributes);
$model->save();
$attributes = ['slug' => $request->input('slug'), 'text_type' => $this->type, 'text_id' => $model->id, 'user_id' => $request->input('user_id')];
$text = Text::create($attributes);
$text->save();
return $this->redirectToIndex();
}
示例10: template
/**
* Create an Excel file to help user fill the
* table to import.
*
* @param Model that instanced
* @return File excel
*/
public static function template(Model $model)
{
$fillable = $model->getFillable();
foreach ($fillable as $key => $value) {
$fillable[$key] = ucwords(str_replace('_', ' ', $value));
}
$upgrades = ExcelHelper::upgrade($fillable);
return ExcelHelper::export($upgrades, $model->getTable());
}
示例11: prepare
/**
*
* @param Model $model
*/
protected function prepare(Model $model)
{
foreach (Input::all() as $name => $value) {
if (in_array($name, $model->getFillable())) {
$model->{$name} = $value;
}
}
}
示例12: update
/**
* @param Model $model
* @param $attributes
* @param bool|true $validate
*
* @return Model
* @throws AttributeNotExist
* @throws ModelNotValid
*/
public function update(Model $model, $attributes = array(), $validate = true)
{
foreach ($attributes as $key => $value) {
if (in_array($key, $model->getFillable(), true)) {
$model->{$key} = $value;
} else {
throw new AttributeNotExist($model, $key);
}
}
if ($model instanceof ValidationInterface) {
if ($validate) {
$this->validate($model);
}
}
$model->save();
return $model;
}
示例13: uploadFileTest
/**
* Upload the file.
*
* @param Model $model
* @param Request $request
*
* @return void
*/
private function uploadFileTest($model, Request $request)
{
// Filter through all the uploaded files, only grabbing the files in our
// Fillable, (we don't want any extra things)
$valid_files = collect($request->allFiles())->filter(function ($file, $key) use($model) {
return in_array($key, $model->getFillable());
});
// For each file process the upload.
// Of course, if the collection of valid_files is empty, nothing will happen.
$valid_files->each(function (\Illuminate\Http\UploadedFile $file, $key) use($model) {
$ext = $file->guessExtension();
$name = Warden::generateUUID() . '.' . $ext;
$fs = new Filesystem();
$fs->makeDirectory($file_path = storage_path('app/uploads'), 0755, true, true);
$model->{$key} = $name;
$file->move($file_path, $name);
});
}
示例14: sortInputAndApply
/**
* @param Model $model This should be an eloquent based thing...
*
* @return Model A newed up model
*/
private function sortInputAndApply(Model &$model, $update = false)
{
// Loop through all input
if ($update) {
foreach (Input::all() as $key => $value) {
// Check to see if there is any available value for the desired model.
if (!empty($model->{$key})) {
// If the value is not equal to the desired value
if ($model->{$key} !== $value) {
// Remove any extra spaces
$model->{$key} = $this->manageInput($key, $value);
}
} elseif (Input::has('_relations')) {
// Explode any potential relations.
$relations = explode(',', Input::get('_relations'));
foreach ($relations as $relation) {
// If the relation has the key, update the value.
if (!empty($model->{$relation}->{$key})) {
if ($model->{$relations}->{$key} !== $value) {
$model->{$relations}->{$key} = $this->manageInput($key, $value);
}
}
}
}
}
} else {
foreach ($model->getFillable() as $key) {
foreach (Input::all() as $field => $value) {
// If the fillable key doesn't match the input
// field keep going,Otherwise, set the values.
if ($key === $field) {
$model->{$key} = $this->manageInput($key, $value);
}
}
}
}
// Unconventional return?
return $model;
}
示例15: getFillable
/**
* Get the fillable attributes for the model.
*
* @return array
*/
protected function getFillable()
{
return $this->model instanceof Builder ? $this->model->getModel()->getFillable() : $this->model->getFillable();
}