my database insert query is as follows
DB::table('job_details')->insert([
'job_id' => $jobId,
'item_id' => $itemId,
'type_id' => $typeId,
'qty' => $qnty,
'laminating' => $laminating,
'mat_id' => $matId,
'rates' => $rates,
'sqft' => $sqft,
'ups' => $ups,
'master_qty' => $masterQnty
]);
and I want to get the status if the query was successful or failed.
The insert method
return a boolean
you can save the result in a variable and check if the result is true.
$queryState = DB::table('job_details')->insert([...])
if($queryState) {
// the query succeed
} else {
// the query failed
}
While performing the DB operations in laravel the method will return a response either true or false also for catching exceptions you can keep the code in try catch block.
try{
$response= DB::table('job_details')->insert([
'job_id' => $jobId,
'item_id' => $itemId,
'type_id' => $typeId,
'qty' => $qnty,
'laminating' => $laminating,
'mat_id' => $matId,
'rates' => $rates,
'sqft' => $sqft,
'ups' => $ups,
'master_qty' => $masterQnty
]);
if($response)
echo 'Query was successfull';
else
echo 'There was some error';
}catch{
print_r($e->getMessage);
}