Jerodev
Jerodev

Reputation: 33186

Laravel redirect back not passing variable

I am creating a simple page to hash strings with md5, however the output is never returned.

This is the controller I use for these pages. The function md5 is routed to the get and the function md5post is routed to the post. The view has a form that is posted to the md5post function. it has one variable $input with the string to hash.

<?php

class ConversionsController extends \BaseController {

    private $withmd5;

    public function __construct(){
        $this->withmd5 = [
            'pagetitle' => 'MD5 hashing',
            'description' => 'description',
            'infoWindow' => 'info',
            'btnSumbit' => Form::submit('Hash', ['class' => 'btn btn-default'])
        ];
    }


    public function md5(){
        return View::make("layout.textareamaster")->with($this->withmd5);
    }
    public function md5post(){

        if (strlen(Input::get("input")) > 0)
        {
            $hash = md5(Input::get("input"));
        }

        return Redirect::back()->withInput()->with("output", $hash);
    }

}

And this is the view

{{ Form::open(['method' => 'post']) }}
    <div class="row">
        <div class="col-md-6">
            <p class="well">
                {{ Form::textarea('input', '', ['class' => 'form-control', 'rows' => 5]) }}
                <span style="float:right;">
                    {{ $btnSubmit or Form::submit('Go', ['class' => 'btn btn-default']) }}
                </span>
            </p>
        </div>
        <div class="col-md-6">
            <p class="well">
                <textarea class="form-control" rows="5" readonly="true">{{ $output or "nothing" }}</textarea>
            </p>
        </div>
    </div>
{{ Form::close() }}

When in my template file, the input is always displayed, however, the variable $output is always undefined. I have beent trying to use other variable names, but it wont work.

If I return the variable right before the redirect, I see the correct output.

Upvotes: 0

Views: 6002

Answers (1)

Jerodev
Jerodev

Reputation: 33186

I have found a solution. In my view I had to use Session::get() to get the value.

That still didn't return the correct output, but I got it by casting this variable to string.

My solution:

{{ (string)Session::get('output') }}

Upvotes: 5

Related Questions