How do I randomise the values that I get from another form?

I have ticket.php and employee.php

In my ticket.php once I create a ticket it will automatically get the employee_id from the employee.php by using arrayhelper but how do I randomise it? once I create a ticket it will get the employee_id randomly? Right now mine is now currently not getting it randomly ids it gets the same id always.

In my ticketcontroller


use app\models\Ticket;

use app\models\Employee;

public function actionCreate()


        $model = new Ticket();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {

            return $this->redirect(['view', 'id' => $model->id]);

        } else {

            $model->time_start = date('y-m-d h:i:s');

            $model->status = ('On Going');

         [b]$model->employee_respond_id = ('id');[/b]

            return $this->render('create', [

                'model' => $model,




There isn’t a really good way to do this. You could query for it and order by Rand() but if you have gaps between your id’s (deleted some) then your random function would select more from the higher numbers and it wouldn’t be truly random. Rand is slow but if you only have a few records it might not be an issue for you.

//we only need the id so to make it efficient as possible using activeRecord only

//select the id and return just the id without the model by using asArray()

$model->employee_respond_id= SomeModel::find()->select(['id'])->orderBy('Rand()')->asArray()->one()['id']