0

I want the rows of a table which have some string 'str' present in a particular column's value.

For ex.- I want all the rows of 'User' table where 'user_name' is 'halku'.

I know about str_contains() and where(), but I want to know how to use them together.

I couldn't find any docs for something like that.

How can I achieve this ?

1 Answer 1

2

In databases this is called a WHERE LIKE statement.

In Laravel you use it like this:

$name = Input::get('name');
$users = User::where('name', 'LIKE', "%$name%")->get();

% is a wildcard. It means get all rows where column name has the word $name and there may be other text before or after that word.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.