jeudi 7 juin 2018

Laravel cookies error

I'm having problems creating a cookie with laravel, the thing is that sometimes the value of this cookie changes into a null intead of its real value which makes my system give errors that I've programed to show in case this cookie dont exist.

This happens when a reaload the page, I've debugged with dd() and every time that I reload the page the value changes from'activo' to 'null' and from 'null' to 'activo', why does this happen?

My code:

    public function store_inicio(Request $request)
{

    $empresa_id = $request->input('empresa_id');
    $empresa = Empresa::find($empresa_id);
    $cierre = $empresa->inicio_caja()->orderBy('id', 'desc')->first();
    if (isset($cierre)) {
        if (!isset($cierre->cierre)) {
            Cookie::queue('estado_caja', 'activo', 180);
            Cookie::queue('numero_caja', $cierre->caja, 180);

        } else {
            $this->crear_inicio($request, $empresa);
        }
    } else {
        $this->crear_inicio($request, $empresa);
    }

    return redirect('ventas');

}

private function crear_inicio($request, $empresa)
{
    $aux_usuario = $request->input('usuario_inicio_caja');
    $usuario = User::where('name', $aux_usuario)->first();
    $numero_caja = $request->input('caja_inicio_caja');
    $valor = $request->input('valor_inicio_caja');
    $inicio_caja = new Inicio_caja();
    $inicio_caja->user_id = $usuario->id;
    $inicio_caja->caja = $numero_caja;
    $inicio_caja->valor = $valor;
    $inicio_caja->save();
    $empresa->inicio_caja()->syncWithoutDetaching($inicio_caja->id);
    Cookie::queue('estado_caja', 'activo', 600);
    Cookie::queue('numero_caja', $numero_caja, 600);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire