php - 带有 Inertia.js 堆栈的 laravel 8 jetstream 未更新配置文件信息
问题描述
我正在将 laravel 8 与带有 Inertia.js Stack 的 jetstream 一起使用。我的数据库字段名称在snake_case 中,我在模板中使用了camelCase。我在配置文件中添加了测试、关于、显示名称和点等新字段。我可以成功保存所有输入的日期,但是当我刷新时,我可以看到显示名称没有带来数据。不知道为什么会这样,如果我在模板和数据库中将 display_name 更改为 snkae_case,那么它会将所有保存的信息带回显示配置文件。任何人都可以请指导我这个。
更新UserProfileInformation.php
<?php
namespace App\Actions\Fortify;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
public function update($user, array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'image', 'max:1024'],
])->validateWithBag('updateProfileInformation');
if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
}
if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'about'=> $input['about'],
'display_name'=> $input['displayName'],
'points'=> $input['points'],
'test'=> $input['test'],
])->save();
}
}
/**
* Update the given verified user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
protected function updateVerifiedUser($user, array $input)
{
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'email_verified_at' => null,
])->save();
$user->sendEmailVerificationNotification();
}
}
这是 UpdateProfileInformationForm.vue
<div class="col-span-6 sm:col-span-4">
<jet-label for="name" value="Name" />
<jet-input id="name" type="text" class="mt-1 block w-full" v-model="form.name" autocomplete="name" />
<jet-input-error :message="form.error('name')" class="mt-2" />
</div>
<!-- Email -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="email" value="Email" />
<jet-input id="email" type="email" class="mt-1 block w-full" v-model="form.email" />
<jet-input-error :message="form.error('email')" class="mt-2" />
</div>
<!-- About -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="about" value="About" />
<jet-input id="about" type="text" class="mt-1 block w-full" v-model="form.about" autocomplete="about" />
<jet-input-error :message="form.error('about')" class="mt-2" />
</div>
<!-- Display Name -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="displayName" value="Display Name" />
<jet-input id="displayName" type="text" class="mt-1 block w-full" v-model="form.displayName" autocomplete="displayName" />
<jet-input-error :message="form.error('display_name')" class="mt-2" />
</div>
<!-- Total Points -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="points" value="Points" />
<jet-input id="points" type="text" class="mt-1 block w-full" v-model="form.points" autocomplete="points" />
<jet-input-error :message="form.error('totalPoints')" class="mt-2" />
</div>
<!-- Test -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="test" value="test" />
<jet-input id="test" type="text" class="mt-1 block w-full" v-model="form.test" autocomplete="test" />
<jet-input-error :message="form.error('test')" class="mt-2" />
</div>
</template>
解决方案
请编写一个 UpdateProfileInformationForm.vue 脚本 http/fetch/axios/form 或 Inertia 使用 post 或获取 dataForm 或 userForm Inertia。现在。->validateWithBag('updateProfileInformation'); 你使用它:
submit() {
this.$inertia.post('/users', this.form)
},
但它会打开对话框响应或捕获 errorsBag / errors 道具
https://inertiajs.com/validation [如果使用惯性] 1
Axios ->validateWithBag('updateProfileInformation'); 是响应错误验证errorsBag/errors
可以在控制器中使用条件
$response->input('name')
return error||pass
推荐阅读
- react-native - React-native:GoogleSignIt 可以,但在 Firebase 的 authGmail 中不显示为空
- python - 在 Python 中运行无限循环的广度优先搜索算法
- node.js - 为什么 Chalk、Node.js 包在 Windows 中无法输出正确的格式?
- cuda - CUDA:在程序执行期间输入参数不变时优化数据传输
- github - VScode 与所有 github 存储库同步(即自动拉取)
- vue.js - 如何从 vue 函数将图像设置为 vue-picture-input
- linux - Scapy:嗅探数据包,修改它,然后发送。数据包从未收到
- html - 显示基于跨度类的图标?
- postgresql - Slick 数据库配置更改为 URL,现在请求很慢
- c - 当我们可以使用 & 运算符传递变量的地址时,为什么要通过指针传递?