0

I have a little problem, my system carries out the copying process when I click on my copy button, but now when I use ex. then wants to reload the page on the new page because for some reason (internet, etc.) the page does not load properly, it copies the same entry again.

Can you somehow block or intercept that this is only triggered when the button is clicked?

Here ist my code snippet:

My UserController.php

public function pduplicate ($id)
    {
        $user = User::find($id);
        $newUser = $user->replicate(["COLUMS_TO_NOT_COPY", "id",  "created_at", "updated_at"]);
        $newUser->save();

        $users = User::all();
        $newId = $newUser->id;

        return view('users.edit', compact('users', 'newId'));
    }

web.php

Route::get('/home/pedit/{id}', [App\Http\Controllers\UserController::class, 'pduplicate']);

View Trigger Button

    <div class="col-sm-2">
        <a class="btn btn-primary" href="/home/pedit/{{ $users->id }}">
            <i class="fas fa-copy"></i> Person kopieren
        </a>
     </div>
Cookie
  • 23
  • 1
  • 7
  • Does this answer your question? [How to prevent form resubmission when page is refreshed (F5 / CTRL+R)](https://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-f5-ctrlr) – Nico Haase Mar 17 '21 at 10:17
  • 1
    Just redirect it to somewhere else after submission. – itachi Mar 17 '21 at 11:38

0 Answers0