Find Controller/Model/Repository by route "string"
Given a route but simply as a string say "route" is there a method that you could say
findControllerByRouteString($route_string)
and it will pull up the controller? I know that you can use Route::getController or you can get your current path. But my scenario is one in which from a page you use ajax to do something and during that call you need to access the controller for the page that is making the ajax call but of course you are now going to get back the path for that ajax call or the controller from that ajax call. The ajax call is made to a controller not associated to the current controller.
When you use Scout normally you create a method in the controller associated to it and do a call to that which returns the searched results, instead I created a ScoutsController that has a method called search.
Currently I am sending through the route_path as a GET request variable and then doing a case check to find the correct Controller.
Which means that from this point forward the ScoutsController needs a way of knowing who the search is for. Since Scout adds in search at the model level from the ScoutsController I just find the Model by the Route Path String provided (see code below). Once I have the model I can run $model->search($search)->paginate(10) this gives me the data I need so I can create a new view to return to the ajax request so it can update the table based on the search.
$.post('/search', {search: search, route_path: '{{ $route_path }}'}, function (data) {
Something to add the issue I'm trying to solve overall is the connection between Scout and Paginate. You can do a search with Scout and thats fine and when you paginate the results that to works good because it will then show not only the page but the query but when you then go to click on the number to go to the next page it is simply loading the index page which now requires excepting request item of "query" and deciding to do a $model->search($query)->paginate(10) instead of $model->paginate(10) what is your solution to this overall? Do you just put all the repeated logic in each controllers index method and call it a day?