我是 Laravel 的新手。我有一個頁面,其中顯示了所有已申請工作的候選人。工作申請.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>每當我單擊編輯按鈕時,它都會顯示錯誤嘗試獲取非對象的屬性“id”這是我的 jobApplications 控制器代碼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 = [];它在線上給出錯誤:$applications = $query->where('job_id', $job->id)->get();根據我可以通過互聯網找到的解決方案,這是因為我試圖將對象類型 ID 分配給數組應用程序。我嘗試將 $jobs 變量上的 first() 更改為 get() 但隨后出現錯誤此集合實例上不存在屬性 [id]。
2 回答

慕村225694
TA貢獻1880條經驗 獲得超4個贊
這里有一個問題:
<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>
{{ }}您忘記了應該圍繞路線()助手的大括號
應該:
<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>

富國滬深
你的
TA貢獻1790條經驗 獲得超9個贊
你的$applicant
是一個收藏
首先,您要迭代$applications
并執行 Blade 中的編輯按鈕,$applicant
而不是$application
.?您的$applicant
變量是一個集合而不是單個項目。
刀片文件錯誤
@foreach
你的刀片文件里沒有盡頭。您可以放在元素@endforeach
后面</tr>
您可以更改應用程序查詢
您可以使用此行簡化您的應用程序
$applications?=?JobActivity::where('job_id',?$job->id)->get();
如果仍然出現錯誤,請檢查變量$job
設置是否正確 - 是否找到記錄并且對象具有屬性 id。也許$slug
變量設置不正確,也證明這個變量。
- 2 回答
- 0 關注
- 160 瀏覽
添加回答
舉報
0/150
提交
取消