Kindly assist me with the use of ->with([]) function

Hi,

I have challenge here. kindly assist me.

With consideration to the image attached

Here is my code
Screenshot from 2023-02-07 10-33-25

Here is output

I the output not to return user password.

So, what can I do to achieve that.

I tried this code but it return null

Codes

              'tblScholarshipsGrantsSponsors.sponsor.user' => function($qr)
              {
                  $qr->select([
                      "name",
                      "email",
                      "username",
                      "phone",
                  ])
                  ->one();
              },

and

              'tblScholarshipsGrantsSponsors.sponsor.user' => function($qr)
              {
                  return $qr->select([
                      "name",
                      "email",
                      "username",
                      "phone",
                  ])
                  ->one();
              },

Here is the output

no need of one() inside with. Add id in select so relation can join and return result.

You can use where() like below example to short the code

->where(['scholarship_category' => 10, 'status' => 30]);
1 Like

Thank you very much my friend for you assistance. it is now working.

Here is the result

2 Likes

by json
-----------_form.php----------------

<?= $form->field($model, 'proveedorporcreten1')->textInput(['maxlength' => 4,'id'=>'codreten']); ?> <?php $script = <registerJs($script); ?>

------------controller -------------
Public function actionImpuesto($codigret)
{
$data[‘impuesto’]=‘’;
$localdata = Impuestcodretenc::find()->where(‘idimpuestcodretenc=’.$codigret)->one();
if ($localdata){

           $data['impuesto']=$localdata->impuestcodretporcent;                 
      }
        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;          
            return $data;
            }