0
votes

How i just want to ask if how can i be able to store another data if i have the same email. i've been making a renting system. after a costumer returned the items, he can be able to send request to rent again. but when i try to submit another form request again. it shows

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'annecurtis@gmail.com' for key 'borrower_requests_email_unique. i already removed the unique() in my the email column on my borrowersRequest table.

how can i do that?

well here is in my controller where costumer submit the data.

 public function store(Request $request)
{
    $rentform = new BorrowerRequest;

    $rentform->user_id = $request->user_id;
    $rentform->car_id = $request->car_id;
    $rentform->borrowers_name = $request->borrowers_name;
    $rentform->email = $request->email;
    $rentform->return_date = $request->return_date;
    $rentform->contact_number = $request->contact_number;
    $rentform->request_status_id = $request->request_status_id;


    $rentform->save();

    $request->session()->flash('message', 'Your Request has been successfully submitted, please wait for a couple of hours for the approval');

    return redirect('/borrowershistory');

anyone pls? thank you. by the way im using laravel and phpmyadmin here.

 public function up()
{
    Schema::create('borrower_requests', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('user_id');
        $table->unsignedBigInteger('car_id');
        $table->timestamps();
        $table->string('borrowers_name', 50);
        $table->string('email');
        $table->bigInteger('contact_number');
        $table->date('return_date');
        $table->unsignedBigInteger('request_status_id')->default(0);
        $table->foreign('user_id')->references('id')->on('users');
        $table->foreign('car_id')->references('id')->on('cars');
        $table->foreign('request_status_id')->references('id')->on('request_statuses');

    });
}
1
you should keep unique the email. Store the customer master data only once (unique email) in a table and the renting table where you store all the rents you use just the id of the user that can be repeated several times. This is a good database design for your task. Helps also in case of updates to the master data (i.e. user changes the email)Lelio Faieta
Can you please share your code for "rent" table. you can simple do one thing, just add the if condition to check the existing record. if the records exists store the email id in rent table.Prathamesh Doke
Hi i already edited my post. what do you mean if condition?chrannbon

1 Answers

0
votes

Drop the column borrower_requests_email_unique and add it again on the table of database if you don't have useful data now.Then it will be not giving issue.