I'm trying to get a student record when the user enters only part of the student's name. In other words, check if one of the current students names contains the string entered by the user, and if so, return that record.
My current code, which return the record only after the user has entered the full name:
public function getStudent($name) {
$std = Student::where('first_name', $name)->get();
return $std;
}
Thanks
You must to use 'like' to get part of the student's name
$std = Student::where('first_name','like', '%' . $name. '%')->get();
Use Like
operator. The LIKE
operator is used in a WHERE clause to search for a specified pattern in a column.
$std = Student::where('first_name', 'like', '%' . $name . '%')->get();
You can visit here for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With