Update insert
This commit is contained in:
@@ -55,36 +55,40 @@ class RequestLogController extends Controller
|
||||
{
|
||||
//insert data to organization
|
||||
try {
|
||||
// Memulai transaksi
|
||||
DB::beginTransaction();
|
||||
|
||||
// Insert data ke tabel organizations
|
||||
$organization_id = DB::table('organizations')
|
||||
->insertGetId([
|
||||
'name' => $request->name_provider,
|
||||
'code' => $request->name_provider,
|
||||
'created_at' => now(),
|
||||
'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Insert data ke tabel addresses
|
||||
$address_id = DB::table('addresses')
|
||||
->insertGetId([
|
||||
'text'=> $request->address_provider,
|
||||
'addressable_type' => 'App\Models\Organization',
|
||||
'addressable_id' => $organization_id,
|
||||
'created_at' => now(),
|
||||
'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Update main_address_id di tabel organizations
|
||||
DB::table('organizations')
|
||||
->where('organizations.id', '=', $organization_id)
|
||||
->update(['main_address_id' => $address_id]);
|
||||
|
||||
// Commit transaksi
|
||||
DB::commit();
|
||||
$request->merge(['organization_id' => $organization_id]);
|
||||
if(!$request->id_provider)
|
||||
{
|
||||
// Memulai transaksi
|
||||
DB::beginTransaction();
|
||||
|
||||
// Insert data ke tabel organizations
|
||||
$organization_id = DB::table('organizations')
|
||||
->insertGetId([
|
||||
'name' => $request->name_provider,
|
||||
'code' => $request->name_provider,
|
||||
'created_at' => now(),
|
||||
'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Insert data ke tabel addresses
|
||||
$address_id = DB::table('addresses')
|
||||
->insertGetId([
|
||||
'text'=> $request->address_provider,
|
||||
'addressable_type' => 'App\Models\Organization',
|
||||
'addressable_id' => $organization_id,
|
||||
'created_at' => now(),
|
||||
'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Update main_address_id di tabel organizations
|
||||
DB::table('organizations')
|
||||
->where('organizations.id', '=', $organization_id)
|
||||
->update(['main_address_id' => $address_id]);
|
||||
|
||||
// Commit transaksi
|
||||
DB::commit();
|
||||
$request->merge(['organization_id' => $organization_id]);
|
||||
}
|
||||
|
||||
$requestLogControllerInstance = new PrimeCenterRequestLog();
|
||||
$response = $requestLogControllerInstance->createNew($request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user