Get the two objects of an array

Asked

Viewed 26 times

0

I receive a request with the following object:

{
 "member_id": 1,
 "lista": [
{
  "id": 1,
  "member_id": 1,
  "instituicao": "Teste Fund",
  "data_inicio": "2018-04-25T06:00:00.000Z",
  "data_termino": "2018-04-25T06:00:00.000Z",
  "cidade": "Sao Paulo",
  "estado": "SP",
  "serie": "5",
  "curso": null,
  "tipo": "fundamental"
},
{
  "id": 2,
  "member_id": 1,
  "instituicao": "Teste Sup",
  "data_inicio": "2018-04-25T06:00:00.000Z",
  "data_termino": "2018-04-25T06:00:00.000Z",
  "cidade": "Belo Horizonte",
  "estado": "MG",
  "serie": null,
  "curso": "Teologia",
  "tipo": "superior"
}
 ]
}

The member_id I’m getting, but the 'List' always arrives.

Method sending the request:

 public function update(AcademicoRequest $request)
{
    $res = $request->all();
    if ( $request->has('member_id') ) {
        $dados_academicos = DB::table('academicos')->where('member_id', $request->member_id)->orderby('id')->get()->pluck('id')->unique()->all();

        $this->destroy($dados_academicos);
    }
    $lista = $res['lista'];

    foreach($lista as $value) {
        Academico::create($value);
    }

    $result = array(
        'message' => 'Os dados foram alterados com sucesso! ',
        'data' => index($res->member_id),
        'success' => true,
    );
    return response()->json($result);
}
  • What is the return of var_dump($res)?

  • Comes an empty [].

  • So what is the return of var_dump($request)?

  • The return is huge, can not share.

  • 1

    Have you tried $request->input('key'); or $request->json('key') ?

  • @Valdeirpsr, using $request->json('key') I got it. Thank you. Put the answer! ^^

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.