What's reason of this error?

Published 1 month ago by alihoushyaripour

I can't describe my problem well, so take a photo:

http://s8.picofile.com/file/8334367950/Screenshot_56_.pngs

This error happen for a route and in every 5 times that I refresh browser, in 4 times this error occur and in 1 time response get backed successfully...

Has anyone ever encountered this problem?!

Notic: I used elasticsearch in controller, I test services and repositories work well and I think error occurred in response resource collection.

Controller class:

public function place(PlaceRequest $request)
{
    // validator
    $request = $request->validated();

    // parameters
    $result = (new MyElastic())->search($request);

    // resource
    $places = PlaceResource::collection($result->places);

    // log

    // result
    return response()->json($places, 200);
}
Best Answer (As Selected By alihoushyaripour)
tykus

@alihoushyaripour surelly? Maybe you should check that and don't assume that it is something that can be handled by PlaceResource::collection, and especially do not assume you can get a places property on $result

Vilfago

Could you post your code, and explain what you tried to achieve.

It's strange that you don't have the error 100% of times.

tykus
tykus
1 month ago (658,320 XP)

When the ElasticSearch fails, or returns no result, what do you actually get back - i.e. what will $result be?

alihoushyaripour

@Vilfago

I don't know how many places founded from search.

if one data found, I should write collection like this?

// resource
$places = PlaceResource::make($result->places);

And if more than one data found:

// resource
$places = PlaceResource::collection($result->places);

Do I have to check how many data has been found from search and write response resource somehow it's suitable for resource?

alihoushyaripour

@tykus

Surelly 'null' get back.

tykus
tykus
1 month ago (658,320 XP)

@alihoushyaripour surelly? Maybe you should check that and don't assume that it is something that can be handled by PlaceResource::collection, and especially do not assume you can get a places property on $result

Please sign in or create an account to participate in this conversation.