The with
method on redirector
saves the data as flash data which is only available for a single request after the redirection. Refer docs
To save the data permanently (until session ends),do this :
$user = DB::select("CALL spGetLOAData('$email')")->first();
$loaData = [
'name' => $user->name . ' ' . $user->surname,
'access' => $user->loa
];
Session::put('loa', $loaData);
return Redirect::to('dashboard');
Redirect::to('dashboard')->with('LOAData',$args);
Just storing flash data. With will be used once, and flushed, you can use Session::put()
instead.
And why dont you store $LOA_data itself to the Session, like:
$LOA_data = DB::select("CALL spGetLOAData('$email')");
Session::put('loa', $LOA_data[0]);
return Redirect::to('dashboard');
Still feel too verbose ? Why not using Eloquent, then you will have your code something like:
$data = LOA::findByEmail($email);
Session::put('loa',$data);
return Redirect::to('dashboard');
In the redirected controller:
return View::make('view name')->with('loa', Session::get('loa', null));
Then in your view:
@if ($loa)
<p class="greeting">{$loa->name}</p>
@if ($loa->isAdmin())
<p>Administrator</p>
@endif
@endif
There are ton of ways to archive it. Above is just a simple examples
bomberman1990>bomberman1990 said:
Still feel too verbose ? Why not using Eloquent, then you will have your code something like:
Eloquent can't be used in this case because as its a stored procedure call.
mcraz said: Eloquent can't be used in this case because as its a stored procedure call.
Why not?
in your eloquent:
function findByEmail($email)
{
$raw = DB::select("CALL spGetLOAData('$email')");
// Do some property parsing here.
}
OK, may be it's not an Eloquent, but somekind of Model. :)
@mcraz and bomberman1990,
Thank you for the help and ideas. I'll give them a try when I get home today and I'll report back.
Thanks again!!
R
mcraz,
OK. I gave it a go and it works. There is a small caveat though. The code has to be modified as follows:
$loaData = [
'name' => $user[0]->name . ' ' . $user[0]->surname,
'access' => $user[0]->loa
];
That's because the stored procedure returns an array object and must be addressed as we fetch the items, otherwise it will fails.
Thank you both for your help.
R.
ralvez said:
mcraz,
OK. I gave it a go and it works. There is a small caveat though.
That's because the stored procedure returns an array object and must be addressed as we fetch the items, otherwise it will fails.
Okay, I thought it would return a collection.
Anyway :
$user = DB::select("CALL spGetLOAData('$email')")[0];
will work !
mcraz,
Yes it works and $user = DB::select("CALL spGetLOAData('$email')")[0] is actually more elegant than:
$loaData = [ 'name' => $user[0]->name . ' ' . $user[0]->surname, 'access' => $user[0]->loa ];
R.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community