I am trying to query with db transaction .When my method run that time data inserted correctly in corresponding table.but it return null.
My Code
return $result = DB::transaction(function() use ($attributes) {
$service = $this->service->create($attributes);
$visibilityAttributes = $attributes['dropdown_option_id'];
$visibilityAttributes = array_map('intval', $visibilityAttributes);
$service->visibility()->sync($visibilityAttributes);
},3);
DB::transaction()
returns whatever the closure passed into it returns. Since your closure doesn't return anything, DB::transaction()
will return null
. You need to add a return
statement to your closure.
return $result = DB::transaction(function() use ($attributes) {
$service = $this->service->create($attributes);
$visibilityAttributes = $attributes['dropdown_option_id'];
$visibilityAttributes = array_map('intval', $visibilityAttributes);
$service->visibility()->sync($visibilityAttributes);
// This value will be returned from DB::transaction().
return $service;
},3);