Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • A little note about your middleware in construct, in your case you can and should assign auth middleware to route group like this Route::middleware(['auth'])->group(function () {... check here. That way your code is cleaner, more maintainable and more compliant with design patterns. About the question: your action function is assigned as get method in routes but you use Http\Request as a function param so change your route to post so that you can get request params from form and add uri param Route::post('/action/{your_param}',... Commented Aug 27, 2020 at 11:54
  • But than again check this it is bad design pattern to use post with uri args, i noticed that your form contains only query arg so make it get Route like so Route::get('/action/{slug}/{query}', ... Commented Aug 27, 2020 at 11:57
  • And again avoid mixing php+html, backend should only return data that frontend than processes however it wants with js it is more maintainable and good design pattern again. Commented Aug 27, 2020 at 11:59
  • @Arman what I have made is a live search with ajax I know some of my practice may be bad since I am new and learning but can you tell me how I can fix this or do it differently and better I will also paste my blade.file. But the problem is in my $route only because if I remove it works perfectly fine and I have it in other pages as well which has a single parameter route where it works perfectly. Commented Aug 27, 2020 at 12:27
  • $.ajax({ url:"{{ route('PackageProgram.action') }}", method:'GET', data: { 'slug': {{ $packageSlug }}, 'query': query },.. and change your route to Route::get('/action/{slug}/{query}', .. and function function action($packageSlug, $query) check with dd() if all args correct Commented Aug 27, 2020 at 12:34