samedi 16 mai 2020

How can call a model method on Eager Loads query

I have this table in my database enter image description here

I want to add an accessor to the quetion_options model for check true or false if this option have in answers table. I wrote these mehods for accessor and get usertest id in question_option model

    public function setUserTestId($id)
    {
        $this->userTestId = $id;
    }
    public function getCheckedAttribute()
    {
        $exist = Answer::where('test_id',$this->userTestId)->where('question_option_id',$this->id)->exists();
    }

I can get questions and otions in any user test id but i dont khonw how can call setUserTestId() method on this query

Question::where('test_id',$test->id)->with('options')->setUserTestId($userTest->id)->get();

this doesnt work correct does any one cant help me?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire