In my model Feedback I have to retrieve the names of my students in alphabetical order.
Do know you where I must to include this line on my code? orderBy('name', 'ASC').
I had several times a synthax problem...
public function index(Request $req)
{
if ($req->search == "") {
$feedbacks = Feedback::paginate(5);
return view('admin.feedbacks.index', compact('feedbacks'));
} else {
$validated = $req->validate([
'search' => 'alpha',
]);
$feedbacks = Feedback::whereHas('students', function($query) use($req) {
$query->where('name', 'like', '%' . $req->search . '%');
})->paginate(5);
return view('admin.feedbacks.index', compact('feedbacks'));
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire