亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

單擊編輯按鈕時嘗試獲取非對象的屬性“id”

單擊編輯按鈕時嘗試獲取非對象的屬性“id”

PHP
30秒到達戰場 2023-08-26 10:07:28
我是 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>


查看完整回答
反對 回復 2023-08-26
?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

你的$applicant是一個收藏

首先,您要迭代$applications并執行 Blade 中的編輯按鈕,$applicant而不是$application.?您的$applicant變量是一個集合而不是單個項目。

刀片文件錯誤

@foreach你的刀片文件里沒有盡頭。您可以放在元素@endforeach后面</tr>

您可以更改應用程序查詢

您可以使用此行簡化您的應用程序

$applications?=?JobActivity::where('job_id',?$job->id)->get();

如果仍然出現錯誤,請檢查變量$job設置是否正確 - 是否找到記錄并且對象具有屬性 id。也許$slug變量設置不正確,也證明這個變量。


查看完整回答
反對 回復 2023-08-26
  • 2 回答
  • 0 關注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號