Home > Mobile >  Getting all the data in the database that was inserted by a single person
Getting all the data in the database that was inserted by a single person

Time:12-13

How can i get all the rows in a database table that was inserted by a logged in person? I'll provide the codes and snippets 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 >
  <div >
   <label for="step2_honor" >Honors</label>
    <div >
     <input  type="text" id='step2_honor' placeholder="Secondary"  value="{!! $user1?->honors !!}" >
     </div>
    </div>
   </div>

What are the other methods I can use to get all the data inserted by the same person? first() method will only get the last inserted row, the get() method throws a Property [honors] does not exist on this collection instance.. For example, in the snippet below app_id 2708 inserted 3 rows, How can i get all the data of in the database that was connected to that person?

enter image description here

CodePudding user response:

Controller

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

Blade

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