-1

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

  • 1
    When you use get() method, you'll have to loop through the results to get the data. That's why you get an error message, "Property [honors] does not exist on this collection instance" – ket-c Dec 13 '22 at 01:09
  • Can you show me how? I edited my post and included the blade file – CaptainCRAZY Dec 13 '22 at 01:16
  • Is the UserModel the only table you have? Because it seems you want to get records from a different table but not the user model table – ket-c Dec 13 '22 at 01:23
  • I got 2 more tables. What is the best practice to do to avoid these errors? – CaptainCRAZY Dec 13 '22 at 01:26
  • I've read the edited post and I've posted answer check it out – ket-c Dec 13 '22 at 01:52
  • Does this answer your question? [Property \[title\] does not exist on this collection instance](https://stackoverflow.com/questions/41366092/property-title-does-not-exist-on-this-collection-instance) – Don't Panic Dec 13 '22 at 02:58

1 Answers1

0

Controller

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

Blade

@foreach($userData as $data)
    {{$data->schoolname}}
@endforeach
lagbox
  • 48,571
  • 8
  • 72
  • 83
ket-c
  • 211
  • 1
  • 10