I would like to insert this code into a flash message, but it seems like flash messages do not accept a flash message
<?php echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?>
<h1>Welcome <?php echo $user->username ?></h1>
<p>Your email: <?php echo $user->email ?></p>
<p>Your account was created on: <?php echo $user->created_at ?></p>
?>
Route::post('registration', array('before' => 'csrf',function()
{
$rules = array(
'username' => 'required|unique:users',
'email' => 'required|email|unique:users',
'password' => 'required|min:8|same:password_confirm'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
return Redirect::to('registration')->withErrors($validation)->withInput();
}
$user = new User;
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
if ($user->save())
{
Auth::loginUsingId($user->id);
return Redirect::to('index')->with('flash_message', 'Thank you for registering. {{ echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?>
<h1>Welcome <?php echo $user->username ?></h1>
<p>Your email: <?php echo $user->email ?></p>
<p>Your account was created on: <?php echo $user->created_at ?></p>
<p><a href="<?= URL::to('profile-edit') ?>">Edit your information</a></p>}}'
);
}
return Redirect::to('registration')->withInput();
}));
How can I do that?
I tried to rename the flash_message and put it under in the master.blade.php like this:
@if(Session::get('login_message'))
<div class='login-message'>{{ Session::get('login_message') }}
<?php echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?>
<h1>Welcome <?php echo $user->username ?></h1>
<p>Your email: <?php echo $user->email ?></p>
<p>Your account was created on: <?php echo $user->created_at ?></p>
<p><a href="<?= URL::to('profile-edit') ?>">Edit your information</a></p> ?>
</div>
@endif
but it did not work, as I guess that I will have to put the php into the routes or into the controller. But I do not know how to do that and I failed to declare the correct variable. Can someone help me?
You're mixing a few coding styles here, and there are elements of your views in your controller which is confusing matters.
Try passing the variables you want to display to the blade view, and then use the {{ $variable }}
notation to include them:
In your action, pass your user back to the view:
// (snip)
if ($user->save())
{
Auth::loginUsingId($user->id);
return Redirect::to('index')
->with('login_message', 'Thank you for registering.')
->with('user', $user);
}
// (snip)
and extract those elements of the user (it's all in the Session
now) in the view:
@if(Session::has('login_message'))
<div class='login-message'>
{{ Session::get('login_message') }}
<h1>Welcome {{ Session::get('user')->username }}</h1>
<p>Your email: {{ Session::get('user')->email }}</p>
<p>Your account was created on: {{ Session::get('user')->created_at }}</p>
<p><a href="{{ URL::to('profile-edit') }}">Edit your information</a></p> ?>
</div>
@endif
That should help you in the right direction.