Support the ongoing development of Laravel.io →
posted 10 years ago
Session
Last updated 2 years ago.
0
Solution

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');
Last updated 2 years ago.
0
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

http://laravel.com/docs/eloquent

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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. :)

Last updated 2 years ago.
0

@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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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 !

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ralvez ralvez Joined 22 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.