1

process: from the student registration (enroll) page (figure 3) should be able to check whether the student paid or not, if not paid Pay button should be visible. else display PAID message.

to do the above process I should check the enroll table (figure 1) student id with the payment table (figure 2) student id,

index controller code:

  public function index()
    {
 $enrolls = Enroll::where('is_paid_admission',1)->orderBy('id','DESC')->get();

  $payments = DB::table('payments')
                ->join('enrolls','payments.enroll_id','=', 'enrolls.id')
                ->where('payments.student_id','=','enrolls.student_id')
                ->get();
         return view('enroll.index',compact('enrolls','payments'));
    }

ERROR Message shows :

 ErrorException (E_ERROR)
Property [student_id] does not exist on this collection instance. (View: C:\wamp64\www\SRVSYS2021\resources\views\enroll\index.blade.php)
Previous exceptions

    Property [student_id] does not exist on this collection instance. (0)

error message

INDEX Page Code if condition:

 @if ( $enroll->student_id == $payments->student_id )
          <td> {{ "PAID" }} </td>
               
          @else
          <td><a href="{{ route('payment.fetch', $enroll->id )}}" class="btn btn-info btn-xs" role="button">  <i class="fa fa-money"> PAY </i></a></td>
          @endif

(All the details have been attached below)

figure 1: Enroll table figure 1: enroll table

figure 2: payments table

figure 2: payments table

figure 3: page view of enrollment table

enrollment page view

I hope you can understand my question. please give me your valuable ideas to solve this problem

QUESTION: I want to compare the student_id on ENROLL_TABLE & PAYMENT_TABLE, and show the payment button if not paid. (payment table only store if the student paid only) whatever the possible answer appreciate

Nuzrath Nalir
  • 79
  • 1
  • 8
  • Your controller passes a variable called `$enrolls` to your view, but the view code you've shown uses `$enroll`. That isn't the problem, so you must be doing something to set `$enroll`, what? The error tells you `$enroll` is a *Collection*, not a model instance, you can check that by eg trying `dd($enroll);` and looking at what is there. Most likely it is the same as `$enrolls`, which is a set of students that you need to iterate over, like `foreach ($enrolls as $enrol) { echo $enrol->student_id; }`. Searching for your error msg will turn up many other questions here with the same problem. – Don't Panic May 25 '22 at 08:06
  • 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 May 25 '22 at 08:06
  • No, as you said the collection is not the solution for me. because I need to get the payment ->student_id == enroll->student_id ,then should check whether the result is available or not?, if it is available show "PAID", else "display Pay button" – Nuzrath Nalir May 26 '22 at 13:27
  • The error is pretty clear: "*Property [student_id] does not exist on this collection instance*". `$enroll` is a Collection (`$payments` is too). You can't do `$enroll->student_id`, and you can't do `$payments->student_id` if those are Collections. You need to iterate over them as I described. The linked question demonstrates the problem and the solution pretty clearly. If that's really not the problem here you need to update your question and show why. – Don't Panic May 26 '22 at 16:55

0 Answers0