Problems to recover data after page redirection

Asked

Viewed 30 times

0

I made a file to store the citizen data in an array, because only in another step will I have confirmation if I should actually store this data

<?php

namespace App\Services;

class CidadaoStore{

    private static $cidadao = Array();

    public static function setCidadao($data){

        //dd($data);
        self::$cidadao = $data;

        return true;
    }

    public static function getCidadao(){

        return self::$cidadao;
    }
}

But if I use get right after set this returns the ok data

if(CidadaoStore::setCidadao($request)){
    dd(CidadaoStore::getCidadao());
    return redirect('/enderecos/create');
}else{
    return back()->with('message', 'Falha ao cadastrar usuário!');
}

But if I try to return the array after page redirection it is empty.

Is there any way I can get the expected effect unused the cache or the database

  • As far as I know php is stateless, ie each request is unique. If you want to keep the state of an object you must save it with some mechanism (Sessions, cache, database, file or any other way). However in your case you can post the data along with redirect. No use Lockable but it sure has something like this. Example Return redirect('/addresses/create', ['citizen' => Citythstore::getCidadao()]). And there on the page from where it was redirected you take the parameter 'citizen'.

  • I’ll take a look at this Sesssions, or I think I’ll go like you said redirect('/addresses/create', ['citizen' => $request]); just from there passing the direct $request

  • Why don’t you send for that other step and do the check there even?

  • You send the data and there in the method send to the next step you want

No answers

Browser other questions tagged

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