Answer the question
In order to leave comments, you need to log in
How to throw an exception on a multidimensional associative array?
There is this code:
User::all()->except(['activated', 'activation_code']);
[
{
"id": 1,
"email": "[email protected]",
"permissions": null,
"activated": 1,
"activation_code": null,
"activated_at": null,
"last_login": null,
"persist_code": null,
"reset_password_code": null,
"first_name": "Artem",
"last_name": "Gavrylenko",
"middle_name": "Yuriyovich",
"post": "main",
"wage": "0.00",
"address": "ул. Пушкина 32, кв.12",
"telephone": "+380934317777",
"date_of_birth": "1997-01-17",
"sex": 1,
"api_token": "",
"created_at": "2015-07-26 08:17:53",
"updated_at": "2015-07-26 08:17:53"
},
{
"id": 2,
"email": "[email protected]",
"permissions": null,
"activated": 1,
"activation_code": null,
"activated_at": null,
"last_login": "2015-07-26 11:37:37",
"persist_code": "$2y$10$Rs0lAWgFGTpSJoNfIy4gmet8rvP.fx\\/tiVyuIzSdlnAC9ieSixdwq",
"reset_password_code": null,
"first_name": null,
"last_name": null,
"middle_name": null,
"post": "",
"wage": "0.00",
"address": "",
"telephone": "",
"date_of_birth": "0000-00-00",
"sex": 0,
"api_token": "0eb9662e88663250b5bccfd06b61b3c12afda40748556562a70c252ea138c845",
"created_at": "2015-07-26 10:42:42",
"updated_at": "2015-07-26 11:37:37"
}
]
Answer the question
In order to leave comments, you need to log in
except на коллекции работает не так.
Тут есть несколько вариантов:
- Сделать presenter, который будет показывать только нужные поля
- Конвертировать всё это дело в массив, и уже работать непосредственно с массивом User::all()->toArray()/User::all()->all(); и вручную фильтровать поля
- Настроить $hidden поле в модели, и скрывать ненужные поля
Я предпочитаю использовать презентеры, которые отображают так, как мне нужно.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question