I have a table named Payments
and another table named Students
with the field name
.
In my Controller Payment, I want to retrieve the student names.
I have this:
public function index(Request $request)
{
$user = $request->user();
$payments = Payment::query()
->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
$query->where('email', $user->email);
})
->when($request->has('search'), function (Builder $query) use ($request) {
$query->where('name', 'like', '%'.$request->input('search').'%');
})
->paginate(5);
return view('admin.payments.index', compact('payments'))
->with('display_search', $user->hasRole('admin'));
}
How do I join the students table?
payment::whereHas('students'
I don't know where I have to put this line
Thank you for your help.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2moJ4IY
via IFTTT
Aucun commentaire:
Enregistrer un commentaire