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

Method to check if current request is a POST request. #1517

Closed
wants to merge 2 commits into from
Closed

Method to check if current request is a POST request. #1517

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 13, 2012

This is much more useful than using Request::method() when updating models. If the request is a POST request, update your model with the input, otherwise render to response.

This is much more useful than using Request::method() when
updating models. If the request is a POST request, update
your model with the input, otherwise render to response.
{
$method = static::foundation()->getMethod();

return ($method == 'POST') ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just return $method == 'POST'?

Copy link

Choose a reason for hiding this comment

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

I'm fast haha

@midned
Copy link

midned commented Dec 13, 2012

I don't really agree with this... There's no much use for checking if the method is a specific one. And if this method is added then must be added is_get is_put and is_delete too.

@ghost
Copy link
Author

ghost commented Dec 13, 2012

It makes life a little easier with these methods.

    public function action_edit($id)
    {
        $post = Post::find($id);

        if(Request::is_post())
        {
            $post->fill(
                'title' => Input::get('title'),
                'content' => Input::get('post')
            );

            $post->save();
        }

        return View::make('post.edit')->with('post', $post);
    }

@midned
Copy link

midned commented Dec 13, 2012

I think you should use RESTful controllers. Use different methods to separate the logic in your code.

@ghost
Copy link
Author

ghost commented Dec 13, 2012

I feel these should only be used if your intentions are to use all of the RESTful methods. You could also get some code duplication by being restricted to using a RESTful controller.

@franzliedke
Copy link
Contributor

Also, read about POST-redirect-GET.

@midned
Copy link

midned commented Dec 14, 2012

@franzliedke 👍

@ghost
Copy link
Author

ghost commented Dec 14, 2012

This is how I have always written my applications in Laravel (with POST-redirect-GET) and I do see how without it there could be issues.

@ghost ghost closed this Dec 14, 2012
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants