0

I'm trying to pass a variable from a controller to another controller I tried using

Redirect::to('dashboard/'.$ssid.'/')->with(compact('wname'))

but does not work any idea how can I achieve this?

here is my code

Route

Route::get('dashboard/{ssid}/', 'HomeController@showDash');

LoginController

public function post_index()
  {

  if(Auth::attempt($credentials)){
    $users = User::where('username','=',$email)->get();
      foreach ($users as $value):
        $activated = $value['a_status'];
        $wname = $value['wholename'];

      endforeach;

      if($activated == 1):
          $red= Redirect::to('dashboard/'.$ssid.'/')->with(compact('wholename')); 
      else:
          $red= View::make('login');
      endif;
      return $red;
}

 }

HomeController

public function showDash($ssid,$wholename)
{
 foreach ($wholename as $userVal):
        $fn = $userVal['firstname'];
        $ln = $userVal['lastname'];
     endforeach;
return View::make('dashboard')->with(compact('fn'));

}

The error I'm having is that Missing argument 2 for HomeController::showDash() as per laravel's debugger..

1 Answer 1

1

Updated answer based on the comments:

public function post_index()
{

    if(Auth::attempt($credentials)){
    $users = User::where('username','=',$email)->get();
    foreach ($users as $value){
        $activated = $value['a_status'];
        $wname = $value['wholename'];
    }
    if($activated == 1) {
        Redirect::to('dashboard/'.$ssid.'/')->with(['wholename' => $wholename]); 
    }

    return View::make('login');
}


public function showDash($ssid)
{
    $wholename = (Session::has('wholename')) ? Session::get('wholename') : [];
    foreach ($wholename as $userVal) {
        $fn = $userVal['firstname'];
        $ln = $userVal['lastname'];
    }
    return View::make('dashboard')->with(compact('fn'));
}

Everything else can stay as is.

Update: fixed erroneous space in 'whole name' (autocorrect did that, sorry).

Sign up to request clarification or add additional context in comments.

6 Comments

hmm but the $wholename would then be visible on the addressbar.. I'm trying to hide it thats why I'm tried using with()..
Ah, I see. In that case you need to pull the variable from the session, it won't be passed in the method call. So: $wholename = (Session::has('whole name')) ? Session::get('wholename') : []; right above the foreach should do it, and remove the $wholename parameter from the method signature.
sorry I'm new to laravel how do I use session in laravel?
using ->with(...) adds it to the session. I will update my answer above.
I see so what I did was actually a session... but that didnt work.. Am I doing something wrong here?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.