Skip to content
Discussion options

You must be logged in to vote

You can use the conditional clauses for this.

$students = Student::query()
    ->orderByDesc('id')
    ->when($request->input('name'), function ($query, $name) {
        return $query->where('full_name', 'LIKE', '%'.$name.'%');
    })
    ->when($request->input('code'), function ($query, $code) {
        return $query->where('national_code', $code);
    })
    ->when($request->input('gender'), function ($query, $gender) {
        return $query->where('gender', $gender);
    });

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AmRo045
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants