Undefined offset error

Asked

Viewed 559 times

0

I have this mistake and I can’t fix it.

ErrorException in VendasController.php line 73:
Undefined offset: 0

//The line that is returning this error: 'default_note' => $client[0]->default_note,

public function index($id = '') {

    $user =  Auth::user();
    $cliente = User::getClientByUser($user->id_cliente, $user->id_loja);

    $data['entidade'] = 'vendedor';
    $data['start'] = '';
    $data['length'] = '';

    $vendedores = Pessoas::getPessoas($data, false);
    $formas_pgto = Vendas::getFormasPgto();
    $estados = Localidade::getEstados();
    $origem = 'venda';

    if(!empty($id) AND is_numeric($id)) {
        $origem = 'orcamento';
        $id_orcamento = $id;
        $orcamento = Orcamentos::getOrcamentos(['id-orcamento' => $id_orcamento]);
        $itens_orcamento = Orcamentos::getItensOrcamentos($id_orcamento);

        $soma_itens = 0;
        $desc_max = 0;

        foreach ($itens_orcamento as $key => $iten) {
            $itens_orcamento[$key]->valor_total = $iten->valor_un * $iten->qtd;
            $desc_max += $iten->desc_max;
            $soma_itens += $iten->qtd;
        }

        $orcamento[0]->soma_itens = $soma_itens;
        $orcamento[0]->desc_max = $desc_max;
        $orcamento[0]->valor_final = $orcamento[0]->valor_total - $orcamento[0]->desconto;
    }

    return view('vendas.frente-caixa', [
        'vendedores' => $vendedores,
        'formas_pgto' => $formas_pgto,
        'estados' => $estados,
        'padrao_nota' => $cliente[0]->nota_padrao,
        'user' => $user,
        'dados_empresa' => $this->DadosEmpresa,
        'orcamento' => empty($orcamento) ? NULL : $orcamento[0],
        'itens' => empty($itens_orcamento) ? NULL : $itens_orcamento,
        'origem' => $origem,
        'id_orcamento' => empty($id_orcamento) ? NULL : $id_orcamento
    ]);
}
  • That one $cliente = User::getClientByUser($user->id_cliente, $user->id_loja); seems not to have returned an array. Gives an dd() or print_r() in $cliente

  • Is it returned empty Array ( ).

  • You need to look at the appointment and $user->id_cliente, $user->id_loja

  • for some reason in the local bank he gives this error,but when I put in the production bank does not happen this mistake.

  • Trying to call the position 0 of the array, because it is non-existent, will cause the error

No answers

Browser other questions tagged

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