这是错误:来自日志:
local.ERROR: Call to undefined method App\Models\User::user() {"userId":14,"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method App\\Models\\User::user() at /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:71)
用户控制器存储函数:
public function Store(Request $request)
{
$request->validate([
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
// 'location' => ['required', 'string', 'max:255'],
]);
$user = \App\Models\User::user()->update($request->all());
if ($user) {
$message = 'Account updated successfully.';
} else {
$message = 'Error while saving. Please try again.';
}
return redirect()->route('profileupdate.user')->with('message', __($message));
}
路由web.php:
Route::prefix('profile')->name('profile')->group(function() {
Route::get('/', [UserController::class, 'Profile'])->name('user.profile');
Route::put('/', [UserController::class, 'Store'])->name('update.user');
});
提交按钮功能:
const submitProfile = () => {
profileForm.put(route("profileupdate.user"));
};
Consol错误:
PUT http://localhost/profile 500 (Internal Server Error)
VM3897:14590 Uncaught SyntaxError: Invalid or unexpected token
Uncaught TypeError: window.ignite is not a function
我试着改变路线方法修补但没什么变化
1条答案
按热度按时间5ssjco0h1#
如果尝试更新用户数据,则需要其ID
并修改路由
然后在您的方法中使用它,如下所示
组件内部
然后您可以访问它,如下所示
大家可以看一下这个例子
https://kollox.com/how-to-pass-laravel-route-to-a-vue-component/