搜尋

首頁  >  問答  >  主體

檢索個人貢獻的全部資料庫記錄

如何取得由登入者插入的資料庫表中的所有行?我將提供下面的程式碼和片段

Controller.php 檔案

#
public function index(){
    $data['user1'] = UserModel::where('seq_id','=',Session::get('loginId'))->first();

    return view ("enrollment-steps.step2", $data,
        [
            'data'=>$data['user1'],
         
        ]);
}

Blade.php 檔案

#
<label><strong> Honors if any(Secondary level): </strong></label>
 <div class="col-sm-12 col-lg-4">
  <div class="form-group row">
   <label for="step2_honor" class="col-sm-3 text-right control-label col-form-label">Honors</label>
    <div class="col-sm-9">
     <input class="form-control" type="text" id='step2_honor' placeholder="Secondary"  value="{!! $user1?->honors !!}" >
     </div>
    </div>
   </div>

我可以使用哪些其他方法來取得同一個人插入的所有資料? first() 方法只會取得最後插入的行,get() 方法會拋出Property [honors] does not exit on this collection instance.。例如,在 app_id 2708 下面的程式碼片段中插入了 3 行,我該如何取得連接到該人的資料庫中的所有資料?

P粉716228245P粉716228245584 天前637

全部回覆(1)我來回復

  • P粉914731066

    P粉9147310662023-09-09 12:48:04

    控制器

    public function index()
    {
        $userData = UserModel::where('app_id', 2708)->get();
        return view('enrollment', compact('userData'));
    }

    刀片

    @foreach($userData as $data)
        {{$data->schoolname}}
    @endforeach

    回覆
    0
  • 取消回覆