search

Home  >  Q&A  >  body text

Retrieve all database records contributed by an individual

How to get all the rows in the database table inserted by the logged in person? I will provide the code and snippet below

Controller.php file

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

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

Blade.php file

<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>

What other methods can I use to get all data inserted by the same person? The first() method will only get the last inserted row, the get() method will throw Property [honors] does not exit on this collection instance.. For example, in the snippet below app_id 2708 has 3 rows inserted, how do I get all the data in the database connected to that person?

P粉716228245P粉716228245432 days ago562

reply all(1)I'll reply

  • P粉914731066

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

    Controller

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

    blade

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

    reply
    0
  • Cancelreply