我想刷新表单提交页面,但不要在Laravel中再次提交

时间:2018-10-08 07:00:02

标签: php laravel laravel-5 html-form

单击“重新提交”后,我想刷新按钮(使用浏览器刷新按钮),但不重新提交该表单

  <form action="{{ route('categories.store') }}" method="POST" role="form">
        {{ csrf_field() }}
            <label for=" name">Category Name</label><span class="required">*</span>
            <input class="form-control input_text" id="name" required placeholder="Category Name" type="text" name="name" value="{{ old('name') }}">
            <label for=" slug">Category Slug</label><span class="required">*</span>
            <input class="form-control slug_text" id="slug" required placeholder="Category Slug" type="text" name="slug" value="{{ old('slug') }}">
            <button type="submit" class="btn btn-primary">Submit</button>
            <a href="{{ route('categories.index') }}" class="btn btn-warning">Back</a>
    </form>

1 个答案:

答案 0 :(得分:1)

您可以使用重定向助手或后退助手。

https://laravel.com/docs/5.7/helpers#available-methods

在您的CategoriesController中:

public function handleFormSubmit (Request $req) {
    // form validations...
    // DB operations...
    return redirect()->route('name.of.route.with.form');
}

OR

public function handleFormSubmit (Request $req) {
    // form validations...
    // DB operations...
    return back();
}

OR

public function handleFormSubmit (Request $req) {
    // form validations...
    // DB operations...
    return redirect()->back();
}