Skip to content

Commit

Permalink
Merge pull request #366 from michalisantoniou6/make-hidden-fields-vis…
Browse files Browse the repository at this point in the history
…ible

Includes hidden fields on update() and create()
  • Loading branch information
eullercdr authored Mar 29, 2017
2 parents 12aadec + e3541c8 commit 5fbab77
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Prettus/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function create(array $attributes)
// we should pass data that has been casts by the model
// to make sure data type are same because validator may need to use
// this data to compare with data that fetch from database.
$attributes = $this->model->newInstance()->forceFill($attributes)->toArray();
$attributes = $this->model->newInstance()->forceFill($attributes)->makeVisible($this->model->getHidden())->toArray();

$this->validator->with($attributes)->passesOrFail(ValidatorInterface::RULE_CREATE);
}
Expand Down Expand Up @@ -576,7 +576,7 @@ public function update(array $attributes, $id)
// we should pass data that has been casts by the model
// to make sure data type are same because validator may need to use
// this data to compare with data that fetch from database.
$attributes = $this->model->newInstance()->forceFill($attributes)->toArray();
$attributes = $this->model->newInstance()->forceFill($attributes)->makeVisible($this->model->getHidden())->toArray();

$this->validator->with($attributes)->setId($id)->passesOrFail(ValidatorInterface::RULE_UPDATE);
}
Expand Down

3 comments on commit 5fbab77

@emko
Copy link

@emko emko commented on 5fbab77 Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change correct? after updating to 2.6.18 i get error
Call to undefined method Illuminate\Database\Query\Builder::makeVisible()
for now i am using previous version

@w0rd-driven
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emko What version of Laravel? I'm on 5.3.31 and makeVisible is part of both Illuminate/Database/Eloquent/Model.php and Illuminate/Database/Eloquent/Collection.php. When I hover over the makeVisible call in BaseRepository in PHPStorm, I see it's calling Model::makeVisible().

I'm not on your version of this package but I have the same BaseRepository changes that seem to work for me as I have hidden fields that aren't throwing an exception. It's possible this change, or others like it, break compatibility with specific Laravel versions depending on when this was introduced.

@emko
Copy link

@emko emko commented on 5fbab77 May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@w0rd-driven Laravel Framework version 5.1.46 (LTS) i see then this works for latest versions, i can just use the current version i am using until when we upgrade to newer Laravel version

my bad sorry guys

Thanks

Please sign in to comment.