简体   繁体   中英

Route Not Passing Parameter to View in Laravel

I have some problem to send parameter from route to view.

The logic:

  1. signup form (firstname, lastname, email) (here is the code)

     public function postCreate(){ $validator = Validator::make(Input::all(), User::$rules); if($validator -> passes()){ //validate function $user = new User; $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); $user->email = Input::get('email'); $user->password = Hash::make(Input::get('password')); $user->level = '1'; $user->save(); return Redirect::to('wizard/'. $user->email)->with('message','Terima kasih telah melakukan registrasi, ' . $user->firstname); } else { ... 
  2. send the parameter email using the route (here is the code)

     Route::get('wizard/{emailid}', array('before' => 'signup', function($emailid) { $email['emailid'] = $emailid; if (isset($email)) { //dd($email); return View::make('console.wizard')->with('email_id', $email); } else { return View::make('signup'); } })); 
  3. consume the email variable to view

i don't have any ideas how this works, i have tried {{ Session::get('email_id') }} , <?php echo $email; ?> <?php echo $email; ?>

how to consume the email variable from route to view (blade=> wizard.blade.php) properly?

First of all, $emailid will always exist with this route. If you had wizard/{emailid?} , then $emailid may be null. In this case, you would want to check if(!empty($emailid)) {} else {} instead of isset($emailid) . The first parameter of ->with() is how you access the variable in your blade.


route.php

Route::get('wizard/{emailid}', array('before' => 'signup', function($email_id) {
    return View::make('console.wizard')->with('email_id', $email_id);
}));

console.wizard.blade.php

Email: {{$email_id}}

GET /wizard/testing should output Email: testing (as long as everything with the before filter signup works).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM