Call to a member function get() on null i need to select * from payment where st_id = 1 and I want display message if database records are empty "cannot found data " like this. but there is a message showing like this
Call to a member function get() on null
My view
<tbody>
@if(!empty($payments))
@foreach ($payments as $payment )
<tr>
<td>{{ $payment->student->FullName }}</td>
<td>{{ $payment->student_id}}</td>
<td>{{ $payment->course->Name}}</td>
<td><img src="{{ asset('images/'.$payment->image_path) }}" alt="recipt image"></td>
<td>{{ $payment->created_at->toDatestring(); }}</td>
<td>
<a href="#" class="btn btn-success btn-circle btn-sm">
<i class="fas fa-check"></i>
</a>
Verified..
</td>
</tr>
@endforeach
@else
<td>Cannot find data</td>
@endif
</tbody>
Controller
public function render()
{
$sid = Auth::user()->id;
$payments = Payment::find($sid)->get();
$courses = Auth::guard('student')->user()->courses()->get();
$students = Auth::guard('student')->user()->get();
return view('livewire.stud-payment',[
'courses'=>$courses,
'students'=>$students,
'payments'=>$payments
]);
}
$payments = Payment::find($sid)->get()
You will trigger another error here. Find only return single model.
Maybe you want to use the where to filter?
$courses = Auth::guard('student')->user()->courses()->get();
Not sure how you define the new guard. But make sure the user and coursers are not empty. Try to use ddd() or logger to debug
ddd(Auth::guard('student')->user(),Auth::guard('student')->user()->courses()->get());
Please sign in or create an account to participate in this conversation.