-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[12.x] Added except() method to Model class for excluding attributes #55072
Conversation
Can you make the logic more like |
foreach ($this->getAttributes() as $key => $value) Am I missing something or this code will ignore virtual
foreach (is_array($attributes) ? $attributes : func_get_args() as $attribute) {
$results[$attribute] = $this->getAttribute($attribute);
} |
@decadence you're right. I can do like this : 🤔 $results[$key] = $this->getAttribute($key); |
So will you fix this please? |
Yes. |
@decadence I don't think it makes sense to include virtual attributes in the except consideration since they are not part of the raw attributes. We access them using the |
@vishal2931 |
Overview
This PR introduces a new
except()
method in the Model class, allowing developers to retrieve model attributes excluding specified keys. This method serves as the inverse of the existingonly()
method, improving usability and convenience when working with model data.Currently, Laravel provides an
only()
method to retrieve a subset of attributes, but there is no built-in way to exclude specific attributes while keeping the rest. This newexcept()
method addresses this gap by working as the inverse ofonly()
, making it easier to manipulate model data efficiently.Example