Question:
How to persist data between two different requests in a controller?

I think the easiest way of doing this will be by using laravel session helper. On the first method, store the orderId like this

public function createOrder(){

     // ... create an $order

     session(['orderId' => $order->id]); 

}


And then on the second one, when you want to retrieve the previously stored order id

public function getStatus(){

      $orderId = session('orderId');

}


Note that if you want to pass a default value to the orderId on retrieval, you can transform the line like this :

$orderId = session('orderId', 'defaultValue'); // The default value can be of any type


Answered by: >Kouassi Henri Joel

Credit:> StackOverflow


Suggested Blogs: 

>How to solve XGBoost model training fails in Python?

>Python Error Solved: load_associated_files do not load a txt file

>How to build interactive_graphviz in Python?

>How to solve encoding issue when writing to a text file, with Python?

>Python Error Solved: pg_config executable not found


Submit
0 Answers

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Why Choose Us ?

We endow businesses with flexible engagement models based on their unique needs. Our strength lies in state-of-the-art technology and affordable consulting services. Try us for fast POCs, full-fledged applications, or technology consulting. Always available for your service.