I am learning Laravel and I am stuck, in fact I have a folder Repositories with a file named StudentRepository.
In my Controller I have this:
public function index(Request $request)
{
$students = $this->students->getAll();
return view('admin.students.index', compact('students'));
}
And in my StudentRepository I have this:
public function getAll()
{
return Student::oldest()->paginate(5);
}
No problem so far...
Now, I would like to improve my Application with the validate system.
In my file StudentRepository I should put this code below:
if ($req->has('search') && !empty($req->search)) {
$validated = $req->validate([
'search' => 'alpha',
]);
$students = Student::where('name', 'LIKE', '%' . $validated['search'] . '%')->orderBy('name', 'ASC')->paginate(5);
$students->appends($req->only('search'));
return view('admin.students.index', compact('students'));
}
On my function getAll() of my folder StudentRepository
public function getAll()
{
return Auteur::orderBy('name', 'ASC')->paginate(5);
}
I really don't understand the syntax to follow?