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