getFillable() public method

Get the fillable attributes for the model.
public getFillable ( ) : array
return array
 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;
 }
Example #2
0
 /**
  * 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);
 }
 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;
 }
Example #4
0
 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;
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 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];
         }
     }
 }
Example #7
0
 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('*');
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * 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();
 }
Example #10
0
 /**
  * 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());
 }
Example #11
0
 /**
  * 
  * @param Model $model
  */
 protected function prepare(Model $model)
 {
     foreach (Input::all() as $name => $value) {
         if (in_array($name, $model->getFillable())) {
             $model->{$name} = $value;
         }
     }
 }
Example #12
0
 /**
  * @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;
 }
Example #13
0
 /**
  * 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);
     });
 }
Example #14
0
 /**
  * @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;
 }
 /**
  * Get the fillable attributes for the model.
  *
  * @return array
  */
 protected function getFillable()
 {
     return $this->model instanceof Builder ? $this->model->getModel()->getFillable() : $this->model->getFillable();
 }