Reputation: 756
A user wants to change his/her password, so he recieved a message in his/her mail that looks like this:
The id in the link is the id of the user from the database, and the forgot token is just random strings that is unique for every user. Here's my route:
Route::get('/changepass/id={id}&forgot_token={token}','LoginController@change_pass');
Route::post('/valid_change','LoginController@valid_change');
Here's my controller
public function change_pass($id,$token)
{
$user = DB::table('users')->where('id',$id)->where('forgot_token',$token)->first();
if($user == null)
return \View::make('/');
else
{
return \View::make('/changepass')->with('id',$user->id)->with('forgot_token',$token);
}
}
public function valid_change()
{
$input = Input::all();
$result_message = '';
$user_id = $input['store_id']; // id of user that is stored in a hidden textfield
$new_password = $input['new_pass'];
$token = $input['store_token']; // token value of a hidden textfield
if (strlen($input['confirm_pass']) >= 7)
{
if($input['confirm_pass'] == $input['new_pass'])
{
DB::table('users')->where('id',$user_id)->update(array('password'=>$new_password));
$result_message = 'match';
}
else
{
$result_message = 'not match';
}
}
else
$result_message = 'length is less than 7';
return Redirect::to('/changepass/id='.$user_id.'&forgot_token='.$token)->with('result_message',$result_message);
}
The update is working fine, but it doesn't give me the $result_message in my changepass.blade.php
<label style="margin-left: 30px; color: indianred;" id="errorMsg">
@if(isset($result_message))
{{$result_message}}
@endif
</label>
I tried using:
return \View::make('/changepass/id='.$user_id.'&forgot_token='.$token)->with('result_message',$result_message);
But it gives me this error:
View [.changepass.id=1&forgot_token=IAytNT7zfW] not found.
So if view::make
is not possible in my case, and I can't get the ->with()
values using redirect(), then what is the alternative way to get the ->with()
values?
Upvotes: 0
Views: 601
Reputation: 3315
You are doing a redirect so you have to use the session()
helper like so:
@if(session('result_message'))
<label style="margin-left: 30px; color: indianred;" id="errorMsg">
{{ session('result_message') }}
</label>
@endif
You can see the doc here
Upvotes: 1