|
|
@@ -21,25 +21,33 @@ class IndexController extends Controller
|
|
|
|
|
|
public function clientInfo(ClientRequest $request) {
|
|
|
$data = $request->validated();
|
|
|
- $client = Client::where('email', $data['email'])->first();
|
|
|
-
|
|
|
- try{
|
|
|
- $chatResponse = ChatGPT::getClientInfo($data['prompt'], $client);
|
|
|
- $images = [];
|
|
|
- foreach ($chatResponse['images'] as $value) {
|
|
|
- try{
|
|
|
- $images[] = Storage::disk('public')->url($client->photos->pluck('path')[$value - 1]);
|
|
|
- } catch (\Exception $exception){
|
|
|
- continue;
|
|
|
+ if ($client = Client::where('email', $data['email'])->first()) {
|
|
|
+ try {
|
|
|
+ $chatResponse = ChatGPT::getClientInfo($data['prompt'], $client);
|
|
|
+ $images = [];
|
|
|
+ if ($chatResponse['images']) {
|
|
|
+ if (!is_array($chatResponse['images'])) {
|
|
|
+ $chatResponse['images'] = explode(',', str_replace(' ', '', $chatResponse['images']));
|
|
|
+ }
|
|
|
+ foreach ($chatResponse['images'] as $value) {
|
|
|
+ try {
|
|
|
+ $images[] = Storage::disk('public')->url($client->photos->pluck('path')[$value - 1]);
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- $chatResponse['images'] = $images;
|
|
|
|
|
|
- return response()->json($chatResponse);
|
|
|
- } catch (\Throwable $th) {
|
|
|
- return response()->json($th->getMessage(), 500);
|
|
|
+ $chatResponse['images'] = $images;
|
|
|
+ $chatResponse['client'] = $client;
|
|
|
+
|
|
|
+ return response()->json($chatResponse);
|
|
|
+ } catch (\Throwable $th) {
|
|
|
+ return response()->json($th->getMessage(), 500);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|