gpt4 book ai didi

php - 如何在 Laravel 5.7 中获取当前用户详细信息?

转载 作者:行者123 更新时间:2023-11-29 09:24:35 24 4
gpt4 key购买 nike

抱歉,我无法发布图片,因为我的声誉低于 10,而且我是新来的。我对此有疑问,我有 2 列,分别是“created_by”和“modified_by”,我想通过用户 ID 进入后端数据库,但它显示了我的错误,我不知道该怎么做了。有人可以帮我吗

    $policy = new Policy([
'id' => $request->get('id'),
'policy_category_id' => $request->get('policy_category_id'),
'policy_title' => $request->get('policy_title'),
'version_no' => $request->get('version_no'),
'policy_details' => $request->get('policy_details'),
'expiry_date' => $request->get('expiry_date'),
'file_path' => $request->get('file_path'),
'created_by'=> auth()->user(),
'modified_by'=>auth()->user()
]);



try {
$policy->save();
} catch (\Illuminate\Database\QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == '1062') {
$status1 = 'failed';
$statusMsg1 = 'Failed to Create, Duplication Code ' . $request->get('code') . '!';
return redirect()->back()->with($status1, $statusMsg1);
}

}

Error ( Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_by' in 'field list' (SQL: insert into company_policy (id, policy_category_id, policy_title, version_no, policy_details, expiry_date, file_path, created_by, updated_at, created_at) values (333, 333, 333, 333, 333, 3333-03-31, 33, {"id":1,"name":"John Smith","email":"john_smith@gmail.com","email_verified_at":null,"created_at":"2019-10-21 01:54:14","updated_at":"2019-10-21 01:54:14"}, 2020-01-20 01:26:41, 2020-01-20 01:26:41)) http://localhost:8089/policy )

最佳答案

以下是获取经过身份验证的用户的详细信息的方法

获取当前用户的所有详细信息

Auth::user() // returns an instance of the authenticated user...

获取当前用户的id

Auth::id()  // returns the id of the authenticated user...

获取当前用户的属性

Auth::user()->firstname
Auth::user()->lastname

关于php - 如何在 Laravel 5.7 中获取当前用户详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59816042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com