Laravel 8:Property [Name] 在此集合实例上不存在
Laravel 8:Property [Name] does not exist on this collection instance
我正在使用 Laravel8。下面是控制器中用于查询的代码
$Applications = Applications::where('applications.Id', $id)
->select(DB::raw("applications.*,attachments.*,attachmentdetails.*"))
->leftjoin('attachments','applications.Id', '=', 'attachments.application_id')
->leftjoin('attachmentdetails','attachments.id', '=', 'attachmentdetails.attachmentId')
->get();
这是 result:In 我能找到的结果 Name
#original: array:24 [▼
"Id" => 1
"id" => 1
"Name" => "test"
"Lastname" => "k"
"Address" => "mansoura"
"Email" => "test@abc.com"
"Nationality" => "Austria"
"Place_of_birth" => "qa"
"Country_of_residence" => "Qatar"
"DOB" => "2021-10-12"
"Workplace" => "austria"
"CV" => "desrts_1634628674.jpg"
"phone_number" => 342343
"photo" => "waterfall_1634628674.jpg"
"ID_attachment" => "logo (2)_1634628674.png"
"AttachmentTypeId" => 1
"status" => 1
"updated_at" => "2021-10-19 07:31:14"
"created_at" => "2021-10-19 07:31:14"
"application_id" => "1"
"attachmentTypeId" => 1
"attachmentId" => 1
"applicationId" => "1"
"attachment" => "I CAN READ HEAD (1).pdf"
]
这是查看页面中的代码:
{{$Applications->Name}}
但在视图中出现错误:
Property [Name] does not exist on this collection instance.
我在执行查询时得到结果..请帮助
当您使用查询生成器的 get
方法时,您会收到 Collection
个结果。
如果要从字面上理解您对 table 的评论,则您正在尝试访问 Collection
结果,就好像它是一条记录一样。
如果您遍历 $Applications
,您将可以访问每一个,然后您的属性将存在。在 Blade 中执行此操作的一种方法是使用 @foreach
循环;我会让你看看如何使用它。
或者,如果您只想检索一个应用程序而没有 Collection
,那么您可以使用 first()
而不是 get()
,您将获得第一个匹配记录。
我正在使用 Laravel8。下面是控制器中用于查询的代码
$Applications = Applications::where('applications.Id', $id)
->select(DB::raw("applications.*,attachments.*,attachmentdetails.*"))
->leftjoin('attachments','applications.Id', '=', 'attachments.application_id')
->leftjoin('attachmentdetails','attachments.id', '=', 'attachmentdetails.attachmentId')
->get();
这是 result:In 我能找到的结果 Name
#original: array:24 [▼
"Id" => 1
"id" => 1
"Name" => "test"
"Lastname" => "k"
"Address" => "mansoura"
"Email" => "test@abc.com"
"Nationality" => "Austria"
"Place_of_birth" => "qa"
"Country_of_residence" => "Qatar"
"DOB" => "2021-10-12"
"Workplace" => "austria"
"CV" => "desrts_1634628674.jpg"
"phone_number" => 342343
"photo" => "waterfall_1634628674.jpg"
"ID_attachment" => "logo (2)_1634628674.png"
"AttachmentTypeId" => 1
"status" => 1
"updated_at" => "2021-10-19 07:31:14"
"created_at" => "2021-10-19 07:31:14"
"application_id" => "1"
"attachmentTypeId" => 1
"attachmentId" => 1
"applicationId" => "1"
"attachment" => "I CAN READ HEAD (1).pdf"
]
这是查看页面中的代码:
{{$Applications->Name}}
但在视图中出现错误:
Property [Name] does not exist on this collection instance.
我在执行查询时得到结果..请帮助
当您使用查询生成器的 get
方法时,您会收到 Collection
个结果。
如果要从字面上理解您对 table 的评论,则您正在尝试访问 Collection
结果,就好像它是一条记录一样。
如果您遍历 $Applications
,您将可以访问每一个,然后您的属性将存在。在 Blade 中执行此操作的一种方法是使用 @foreach
循环;我会让你看看如何使用它。
或者,如果您只想检索一个应用程序而没有 Collection
,那么您可以使用 first()
而不是 get()
,您将获得第一个匹配记录。