-2

Currently working on a personal project and solving a scenario where on submitting the form a signed URL(action link) is emailed to user, once that link is opened by user and form in that URL is submitted, what I am trying to achieve and facing issue in development is, if anyone again opens that link after submission of form they are shown a screen like which maybe saying your response is submitted. Any hint about that does this kind of functionality is possible to be built with Laravel or which topic I should be searching for that can make me able to understand how to solve such scenarios. Any suggestion or hint would be highly appreciated. Thanks.

  • @brombeer Thanks for your suggestion, but I have no where asked for referring me to that documentation as I have mentioned already that I have implemented signed URL and its working. – ABDUL SALAM Dec 30 '21 at 15:11
  • The title of your post is "_How to expire or disable link once the response on that particular link is submitted by user?_" - if that's not what you're actually asking you might want to change it. What _is_ your actual question then? If it is "_if anyone again opens that link after submission of form they are shown a screen like which maybe saying your response is submitted_" you might want to read a little further, section "_Responding To Invalid Signed Routes_" – brombeer Dec 30 '21 at 15:18

1 Answers1

2

This is a common operation in laravel and you can handle this easily with controllers. The standard way is:

you should create a link and save it on your database. Add a field named isSubmitted . Also, I highly recommend you to have expiration_date field for that link in database.

Create a new migration with artisan using this command:

php artisan make:migration links

Then, add your favorite fileds to migration:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class LinksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('links', function (Blueprint $table) {
            $table->id();

            $table->text("url");
            $table->boolean("is_submitted")->default(false);

            $table->timestamp("expiration_data")->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('links');
    }
}

In next step, when you are submitting that form, in your controller, change the status of isSubmitted field and save it on the database again. On next call of url, you can handle the request according to isSubmitted field

Mohammad Taheri
  • 348
  • 2
  • 9