I want to store result of a query in a session (or any global) variable, so that I can retrieve that variable from different controller or action in laravel 5.1. I'll take some time to explain it further, what's happening here is I am getting some data from the form, and after that I have to get some more data from a different page and perform a DB transaction only then. Earlier I used Zend Framework in which we had a storage object in which one could store data in almost any format. Here is my code snippet.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Auth;
use Illuminate\curl\CurlRequestHandler;
use Config;
class MyController extends Controller
{
public function myajax(Request $request)
{
$data = "Some Data From DB operation";
Session::put('myFormData', $data2);
$value = Session::get('abcd');
print_r($value); //Works Fine
}
public function someOtherFunction(Request $request){
$val = Session::get('myFormData');
print_r($val);die('check');
// No data !
}
How do I get that data? I guess every time it hits a new action, session value is restored to default. Is there any other way to do so?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire