I am creating a system which create 2 things. An organization in the organization table and a profile in the profile table.
The point would be that when you create an organization, it automatically creates you a profile.
So I have a route that creates an organization and one that create a profile. Should I call my route inside a transaction, should I call the static function instead of the route.
I am kinda lost and I wanna make sure that if one save() gets an error, everything is reversed. I read about transaction and rollback and I'm not really sure how to go
public function Create(Request $request)
{
$validatedData = $request->validate([
'address' => ['required', 'max:255'],
]);
$org = new Organization();
$org->address = $validatedData['address'];
$org->save();
// Create the profile would be here, be either calling the route or the function that is called by the route
}
Here is my orgnization function, it's really simple.
I just wanna make sure to go the right way and the most optimized one