Home > Mobile >  Query to pass data to the edit view
Query to pass data to the edit view

Time:01-07

I need to pass data to the "edit" view from the "index" view, the data are from two different related tables (table "personas" parent and table "residentes" child) so i'm working in the "edit()" method in the residentesController and i couldn't find a way to pass the data in a single object, is it possible to do it? if there is not What is the best way to do it?

//in the ResidentesController //this is what i currenly have

 public function edit(Residente $residente)
    {

        $persona = Persona::find($residente->persona_id);


        return Inertia::render(
            'Residentes/Editar',
            [
                'residente' => $residente,
                'persona' => $persona
            ]
        )

}

CodePudding user response:

If i understand correctly your question you need to load the relationship you need in the original query (keep in mind to create it in the model classes)

$persona = Persona::with('residentes')->find($residente->persona_id);

and after that you can create the variable

$residente = $persona->pluck('residentes');
  • Related