Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 find return only first five record

Am using yii2 find() and would like to return only first five records

THIS IS what ive tried

 $items= \frontend\models\TblResearch::find()->orderBy("id")->all();

That returs all the records what am looking for is

 $items= \frontend\models\TblResearch::find()->orderBy("id")
        ->all(); //instead of all use like something to return five records

How do i go about this

I would like only to use the model approach not the sql

like image 493
Geoff Avatar asked Dec 22 '25 23:12

Geoff


1 Answers

Use limit()

$items= \frontend\models\TblResearch::find()->orderBy("id")->limit(5)->all();

like image 73
Jigar Avatar answered Dec 24 '25 15:12

Jigar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!