gpt4 book ai didi

php - 单击编辑按钮时尝试获取非对象的属性 'id'

转载 作者:行者123 更新时间:2023-12-02 19:21:01 28 4
gpt4 key购买 nike

我是 Laravel 新手。我有一个页面,其中显示了所有已申请工作的候选人。

job-applications.blade.php

<table class="table table-hover table-striped" id="dataTable" style="font-size: 13px !important">

<thead>
<th style="padding:5px 22px 10px 6px !important">Candidate</th>
<th style="padding:5px 22px 10px 6px !important">Status</th>
<th style="padding:5px 22px 10px 6px !important">Edit</th>
</thead>

<tbody>

@foreach ($applications as $application)

<tr>
<td>
<a class="text-center" href="{{ route('candidates.show', $application->user->username) }}"

target="_blank" class="text-theme">{{ $application->user->name }}</a>
</td>

<td>
{{ $application->status }}
</td>

<td>
<a href="route('employers.applicants.edit', $applicant->id)" class="mt-1 text-center btn-sm btn btn-outline-yellow"> <i class="fa fa-pencil"></i> Edit</a>
</td>
</tr>
</tbody>
</table>

每当我单击编辑按钮时,它都会显示错误

Trying to get property 'id' of non-object

这是我的 jobApplications Controller 代码

public function jobApplications($slug)
{
if (!Auth::check()) {

session()->flash('error', 'Sorry !! You are not an authenticated Employer !!');

return back();
}

$user = Auth::user();

$user_id = $user->id;

$applicant = DB::table('job_activities')->where('user_id',$user_id)->get();

$job = Job::where('slug', $slug)->first();

$expreience_data = Experience::all();

$query = JobActivity::query();

$applications = $query->where('job_id', $job->id)->get();

$experiences = [];

$education = [];

$application_data = [];

foreach ($applications as $application) {

// Filter

if (isset(request()->exp)) {

$exp_data = CandidateProfile::with('experience')->where('experience_id', request()->exp)->where('user_id', $application->user_id)->first();


if ($exp_data) {

$experiences[] = $exp_data;

$education[] = UserQualification::where('user_id', $application->user_id)->first();


$application_data[] = $application;

$filter['exp'] = request()->exp;
}

}else{

$experiences[] = CandidateProfile::with('experience')->where('user_id', $application->user_id)->first();

$education[] = UserQualification::where('user_id', $application->user_id)->first();

$application_data[] = $application;
}
}

$education = $education ? $education[0] : [];

$experience = $experiences ? $experiences[0] : [];

$applications = $application_data;

return view('frontend.pages.employers.job-applications', compact('user', 'applicant', 'job', 'applications','experience', 'education', 'filter', 'expreience_data'));

}

它在线上出现错误:

$applications = $query->where('job_id', $job->id)->get();

根据我可以在互联网上找到的解决方案,这是因为我试图将对象类型 ID 分配给数组应用程序。我尝试将 $jobs 变量上的 first() 更改为 get() 但随后出现错误

property [id] doesn't exist on this collection instance.

最佳答案

这里有一个问题:

<a href="route('employers.applicants.edit', $applicant->id)" class="mt-1 text-center btn-sm btn btn-outline-yellow">
<i class="fa fa-pencil"></i> Edit
</a>

你忘记了应该包围route()助手的大括号{{ }}

应该是:

<a href="{{ route('employers.applicants.edit', $applicant->id) }}" class="mt-1 text-center btn-sm btn btn-outline-yellow">
<i class="fa fa-pencil"></i> Edit
</a>

关于php - 单击编辑按钮时尝试获取非对象的属性 'id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63063187/

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