laravel, mysql transaction not working after failed one time

I am performing insertion in 4 tables simultaneously using laravel 5.8. When I Submit incomplete Form it will show me error and after that when submit proper data again it will show database error

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`matrimonial_db`.`personal_details`, CONSTRAINT `personal_details_ibfk_1` FOREIGN KEY (`site_user_id`) REFERENCES `siteuser` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) (SQL: insert into `personal_details` (`site_user_id`, `updated_at`, `created_at`) values (148, 2020-04-29 05:16:53, 2020-04-29 05:16:53))

First time when i fill form it insert data successfully in all tables but when try again it will show me the error. here is a code

try
{
$connection = DB::connection('mysql');
$connection->beginTransaction();
$userData = session()->get('registeruser_data');
$userData->user_type = 'v';
$userData->save();

$personal_details= new PersonalDetail;
$personal_details->site_user_id =$userData->id;
$personal_details->save();

$personal_bio= new PersonalBio;
$personal_bio->site_user_id =$userData->id;
$personal_bio->save();


$partner_details= new PartnerDetail;
$partner_details->site_user_id =$userData->id;
$partner_details->save();

$personal_img= new PersonalImage;
$personal_img->site_user_id =$userData->id;
$personal_img->save();

$connection->commit();
session(['siteuser' => $userData->id]);
return redirect('/edit/profile');
// dd($charge);

}
catch(Exception $ex)
{
$connection->rollBack();
return redirect::back()->withErrors(['stripe'=>$ex->getMessage()]);
}

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2ShO3YF
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.