aGreenCoder's avatar

Date And Multiple Field Filter Through SPATIE query builder for post request

I go through 'SPATIE query builder' documentation and find they cannot describe properly how to post methods implemented. I need to filter data based on multiple parameters including the data add date filter, and I am using the POST method, How I can achieve this for 'SPATIE query builder'.

I can Filter 1 field by writing below code

$data = QueryBuilder::for(EmpData::where('empAddedByAgent', $request->searchAgent))
                ->get();

The form Look Like Below Image https://www.awesomescreenshot.com/image/23496415?key=06f5bda4269400354afa2d1690557544

0 likes
7 replies
Snapey's avatar

You shouldn't return data based on a POST request, so why are you trying to use it this way (with POST) ?

aGreenCoder's avatar

@Snapey I can return data in post method by define ->allowedIncludes(['posts']) according their documentation

Snapey's avatar
Snapey
Best Answer
Level 122

@DevWebTK its not good practice. You should always return a redirect at the end of a post request.

Why do you not set your form to action="GET" ?

Snapey's avatar

@DevWebTK

I can return data in post method by define ->allowedIncludes(['posts']) according their documentation

This has NOTHING to do with making http POST requests

aGreenCoder's avatar

Currently, I can fetch data using the get method, but how add the filters?

$data = QueryBuilder::for(EmpData::class)
                ->allowedFilters('name')
                ->get();

Please or to participate in this conversation.