How to GET newest records ?

I want to send request to users endpoint that should give me 10 newest users in my system.

I am following documentation, and my request is like this: http://localhost/api/users/5?expand=profiles

Even further, what if I want to get 10 users with newest profiles. So user do not need to have profile created, and I wan to get latest 10 with fresh profiles.

Does anyone have any clue what is the right way to do this ?

I assume that you use User controller and the action that give back the last 10 user is index and you api user model is in \api\modules\v1\models\

I assume also that you have an “active” column to know if the user is active and that you have a ‘creation_date’ column as well.

class UserController extends ActiveController {

  public function actions() {

    	$actions = parent::actions();

    	$actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];

    	return $actions;


  public function prepareDataProvider() {

    	$query = \api\modules\v1\models\User::find()




    	return new \yii\data\ActiveDataProvider([

        	'query' => $query,

        	'pagination' => false, // just in case you have a pagination under 10 elements