I have a little question here. This is my code:
JavaScript
x
DB::beginTransaction();
try{
$created = new TransportTypeColumn();
$created->name = $translated_ids[0];
if(!$created->save())
throw new Exception("failed saving transport type column");
DB::commit();
return response()->json(['success'=>'Property has been created successfully', 'data'=>$created],200);
}catch(Exception $e){
DB::rollback();
return response()->json(['error'=>'Something went wrong, please try later.'], 500);
}
so do I need this piece of code ? :
JavaScript
if(!$created->save())
throw new Exception("failed saving transport type column");
or does it throws exception itself if save() function doesn’t succeed?
Advertisement
Answer
save
returns a boolean, you need to check if the save was successfull or not, but unless there is a mysql error you won’t get any exceptions.