How can I prevent multiple submissions when a submit button is hit very fast?
This is my store
function:
public function store()
{
$input = Input::except('_token');
$country = new Country($input);
$country->save();
}
I thought about adding validation for unique ids. But I thought that if the same method is executed several times each Country
instance will be different, hence will have different ids, so the entry will be created anyway. I don't like the idea of using validation for this situation anyway.
I have something around that prevents multiple submissions when updating an entity:
public function updatePost(Post $post) {
if (count($post->getDirty()) > 0) {
$post->save();
return Redirect::back()->with('success', 'Post is updated!');
} else {
return Redirect::back()->with('success', 'Nothing to update!');
}
}
However, getDirty()
wouldn't be of any help when storing a new entity.
I have been searching for a while and I didn't find anything straight forward.
What is the usual way to deal with this issue?
edit. tried using Redirect::route()
but I got the same results.