1

I'm figuring out how to work with Lumen (a stripped Laravel framework) and am a bit stuck on the ORM / query builder.

I have the following function, which currently isn't working, and want it to display all the users starting with the letter 'b'.

public function getUsers()
{ 
    $users = User::where('name', 'b%')->get();
    return response()->json($users);
}

How do I approach this? I'm so used to plain SQL that I'm confused about this query builder. So how do I fetch all the users starting with the letter 'b'?

Thank you for taking the time to read and hopefully answer my question.

Serellyn
  • 405
  • 1
  • 9
  • 26

1 Answers1

7

Use where method with like:

$users = User::where('name', 'like', 'b%')->get();
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279