jeudi 1 novembre 2018

How can i change key id in method class orm Laravel?

Maybe is not possible but i have in table answers for radio input with id of question and answer like id = 36 , answer = Yes. My code below get all answers

public function getAnswer() {
        return $this->hasMany('App\Answer', 'user_id', 'id')
            ->with('question')
            ->whereHas('question.group', function($query) {
                $query->where('name', 'simple_quesion');
            });
    }

and i have collection which is ok

#items: array:9 [▼
    0 => getAnswer {#400 ▶}
    1 => getAnswer {#401 ▶}
    2 => getAnswer {#402 ▶}

but is any way to get keys and assign with this collection like

#items: array:9 [▼
        35 => getAnswer {#400 ▶}
        37 => getAnswer {#401 ▶}
        42 => getAnswer {#402 ▶}

in this method public function getAnswer() ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire