How can I search for a record using a part of a string field in Laravel/Eloquent?

You must to use 'like' to get part of the student's name

$std = Student::where('first_name','like', '%' . $name. '%')->get();

You should use the wildcard LIKE

$std = Student::where('first_name','like', '%'.$name.'%')->get();

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

There are two wildcards often used in conjunction with the LIKE operator:

% - The percent sign represents zero, one, or multiple characters

_ - The underscore represents a single character

Finds any values that have "or" in any position

$students = Student::where('first_name', 'LIKE', '%' . $name. '%')->get();

You can do it as well - whereLike

$students = Student::whereLike('first_name',$name)->get(); 

Tags:

Php

Laravel