1

I understand that to do a select query is

$bearLawly = Bear::where('name', '=', 'Lawly')->first();

but how to I do a select query such as

SELECT * FROM bear where name = 'abc' AND age => '5' AND title = 'kid' ORDER BY name LIMIT 5, 10

Thanks!

2 Answers 2

1

You may try this:

$bearLawly = Bear::where('name', 'abc') // By default = will be used, so optional
                 ->where('age', '>=', '5')
                 ->where('title', 'kid')
                 ->orderBy('name') // or orderBy('name', 'desc') for reverse
                 ->take(5)->skip(10)->get();

According to following query:

SELECT * FROM bear where name = 'abc' AND age => '5' AND title = 'kid' ORDER BY name LIMIT 5, 10
Sign up to request clarification or add additional context in comments.

Comments

0

Just chain them:

$bearLawly = Bear::where('name', 'Lawly')->where('age', '5')->first();

1 Comment

what if i don't want just the first found but 'ORDER BY name LIMIT 5, 10' ?

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.