Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added better back request method #210

Merged
merged 1 commit into from
Jul 10, 2018
Merged

Conversation

josephmancuso
Copy link
Member

This PR adds a better back method than previous. You can use this like so:

a lot of the time we might have a route like this:

ROUTES = [
    get('/dashboard/create', 'Controller@show'),
    post('/dashboard/create', 'Controller@store')

]

meaning we have a GET route that shows the create form and then a POST method on the same route. In this instance we can just do this:

def store(self):
    request().back()

Which returns the current URL as the redirection but it will be the GET version of it.


We can also specify more explicitly what the redirection will be by using a view helper function:

<form action="{{ route('dashboard.create')" method="POST">
    {{ csrf_field|safe }}
    {{ back('/dashboard/create')|safe }}
</form>

or possibly even:

<form action="{{ route('dashboard.create')" method="POST">
    {{ csrf_field|safe }}
    {{ back(request().path)|safe }}
</form>

and then the back method will look for this new input:

def store(self):
    request().back() # returns the __back input created from the view helper

We can also specify a default just incase one is not passed in:

def store(self):
    request().back(default='/login') # returns the __back input created from the view helper or /login if that didn't exist.

@josephmancuso josephmancuso self-assigned this Jul 8, 2018
@coveralls
Copy link

coveralls commented Jul 8, 2018

Coverage Status

Coverage increased (+0.08%) to 91.359% when pulling a4f2c2d on create-better-back-method into b259858 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 91.359% when pulling a4f2c2d on create-better-back-method into b259858 on master.

@josephmancuso josephmancuso requested a review from aisola July 8, 2018 18:38
Copy link
Contributor

@aisola aisola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple. I like it.

@josephmancuso josephmancuso merged commit 7334ba5 into master Jul 10, 2018
@josephmancuso josephmancuso deleted the create-better-back-method branch July 11, 2018 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants