Files
cheerstothe_season_2.0/app/Services/APIs/CustomerAPIs/ContactUsApiServices.php
sayliraut e92f23844c change
2024-05-24 19:40:36 +05:30

49 lines
1.6 KiB
PHP

<?php
namespace App\Services\APIs\CustomerAPIs;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Models\IamPrincipal;
use App\Models\ManageContactus;
use Throwable;
class ContactUsApiServices
{
public function addCustomerRestaurantContactForm($request)
{
try {
DB::beginTransaction();
//create user_data
$user_data = IamPrincipal::where('id', $request['iam_principal_id'])->first();
if ($user_data) {
// Create a new instance of ManageContactus model
$contact = new ManageContactus();
$contact->principal_xid = $user_data->id;
$contact->name = $request->name;
$contact->email = $request->email;
$contact->message = $request->message;
// Save the contact data
$contact->save();
DB::commit();
//response data
Log::info('Contact form data Created successfully');
return jsonResponseWithSuccessMessageApi(__('success.save_data'), [], 201);
} else {
Log::error('Contact not found in addVendorContactForm.');
return jsonResponseWithErrorMessageApi(__('auth.validation_failed'), 403);
}
} catch (Throwable $ex) {
DB::rollBack();
Log::error('Contact API failed : ' . $ex->getMessage());
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
}
}
}