株式会社SCOUTER @kotamat
だけkotamats
エージェント
転職者
求人企業
エージェント
転職者
求人企業
面接・履歴書では
わからない転職者の
リファレンスチェック
class PostFormRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required',
];
}
}
class FormController
{
public function __invoke(PostFormRequest $request)
{
return $request->validated();
}
}
class PostFormRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required',
'user.parent.children.*.name' => 'required',
];
}
}
try {
await this.$axios.$post('/form', payload)
} catch (err) {
if (err && err.response && err.response.status === 422) {
this.err['user.parent.children.0.name'] =
err.response.data.errors['user.parent.children.0.name']
}
}
非常に冗長
var street = user.address && user.address.street;
var fooInput = myForm.querySelector('input[name=foo]')
var fooValue = fooInput ? fooInput.value : undefined
var street = user.address?.street
var fooValue = myForm.querySelector('input[name=foo]')?.value
try {
await this.$axios.$post('/form', payload)
} catch (err) {
if (err && err.response && err.response.status === 422) {
this.err['user.parent.children.0.name'] =
err.response.data.errors['user.parent.children.0.name']
}
}
try {
await this.$axios.$post('/form', payload)
} catch (err) {
if (err?.response?.status === 422) {
this.err['user.parent.children.0.name'] =
err?.response?.data?.errors['user.parent.children.0.name']
}
}
{
"staff.0.id": ["The id field is required."],
"staff.0.name": ["The name field is required."],
"staff.1.id": ["The id field is required."],
"staff.1.name": ["The name field is required."],
}
{
"staff": {
"0": {
"name": ["The name field is required."],
"id": ["The id field is required."],
},
"1": {
"name": ["The name field is required."],
"id": ["The id field is required."],
}
}
}
if (err?.response?.status === 422) {
this.err = convertValidationError(err?.response?.data?.errors)
}
if (err?.response?.status === 422) {
this.err['user.parent.children.0.name'] =
err?.response?.data?.errors['user.parent.children.0.name']
}
<div
v-for="child in err?.user?.parent?.children || []"
class="error"
>
{{ child.name}}
</div>
err?.user?.parent?.children || []
Raw expression: v-for="child in err?.user?.parent?.children || []"
1 |
2 | <div>
3 | <div v-for="child in err?.user?.parent?.children || []" class="error">
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | {{ child.name }}
5 | </div>
import o from 'optional-value'
const someObject = {
foo: {
bar: 'hoge'
}
}
const value = o(someObject, 'foo.bar')
// => hoge
const noneValue = o(someObject, 'foo.boo')
// => null
const obj = o(someObject, 'foo')
// => {bar: 'hoge'}
<div
v-for="child in err?.user?.parent?.children || []"
class="error"
>
{{ child.name}}
</div>
<div
v-for="child in o(err, 'user.parent.children') || []"
class="error"
:key="child.name"
>
{{ child.name }}
</div>