Issue
This url after i am filtering data using date (wherebetween) http://127.0.0.1:8000/viewMonth/filter?_token=9jmqgiLCKNTMKtwObhlVQXCR6Vj1zcrDwsdXDDbm&dateFrom=2022-01-17&dateTo=2022-01-17
Now I am making a new function called SearchData, how i suppose to do if i want to display SearchData from the filtered date http://127.0.0.1:8000/viewMonth/filter?_token=9jmqgiLCKNTMKtwObhlVQXCR6Vj1zcrDwsdXDDbm&dateFrom=2022-01-17&dateTo=2022-01-17/{SearchData}
And this is my route
Route::get('/viewMonth/filter/search', 'App\Http\Controllers\InvoiceController@SearchReportMonth')->name('SearchReportMonth');
Route::get('/viewMonth/filter', 'App\Http\Controllers\InvoiceController@filterDateMonth')->name('filterDateMonth');
Solution
I would recommend just returning the page with the new filtered data (unless you need it to be more complex like a HTTP Request from JS for the content which I would assume you know how to handle)
an example of this is as such:
Only an example of how its done, implementations vary depending on needs
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$query = User::query();
if (request('search')) {
$query
->where('name', 'like', '%' . request('search') . '%')
->orWhere('email', 'like', '%' . request('search') . '%')
->orWhere('id', 'like', '%' . request('search') . '%');
}
if ($request->has(['field', 'sortOrder']) && $request->field != null) {
$query->orderBy(request('field'), request('sortOrder'));
}
// Ignore my InertiaJS implementation, will work the same with base Blade Files.
return Inertia::render('Users/Index', [
'users' => fn() => $query->paginate(10)->withQueryString(),
]);
}
Essentially I use request()
to grab the query parameters and then construct my DB query from there and return the data it found. Hope this helps, by all means just ask if you need more of an understanding or have questions!
Answered By - MysticSeagull
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.