2 years ago

Return back to edit form with old url

Posted 2 years ago by baguus

Hi guys I'm trying to add a funcionality to return back after several edits. I want to add a Back button to edit form after update. When a user selects edit (from list of products or from single product) edit form is shown. At the end there is a Cancel button with {{ URL::previous() }}. This works.

After user completes first edit I return to edit form with flash message of success. I then change the "Cancel" button to "Back". I compare current and previous url. This works.

Now I have a problem on how to set the original url. I tried setting it in session. And it works in first iteration. In second iteration it gets overwritten.

I tried with setting the url in form request, but that didn't work as desired either. The url gets overridden.

Is there some nice way to acheive this?

in my edit.blade I have

@if(url()->current() != URL::previous())
        {{ Session::put('myreferrer', URL::previous()) }}
        <a href="{{ URL::previous() }}" class="btn">Cancel</a>
    <a href="{{ Session::pull('myreferrer') }}" class="btn">Back</a>

This works with "button" but not with url.

Yes I know best practice would be to return to previous page after edit... :)

Please sign in or create an account to participate in this conversation.