Filters in Laravel 4 - laravel

I'm trying to use a pattern based filter in my routes file.
I want to stop anything without crsf and only allow ajax calls.
So far I have:
Route::when('/gateway/*', 'crsf');
I'm not sure where im going wrong and how i could add in the ajax verification.

You can use Route Groups to apply before filter.
http://laravel.com/docs/routing#route-groups
You can check if a request is ajax or not by calling if(Request::ajax). Define this on your before call.
http://laravel.com/docs/requests
As for the patterns, have a look at Pattern Based Filters section of Routing documentation.
http://laravel.com/docs/routing

Related

Calling a controller/action through query parameters

Is it possible to call a controller and action directly by using query parameters in Laravel? I see some frameworks allow /index.php?_controller=X&_action=Y, or Yii allows /index.php?r=X/Y. I was wondering if something similar was possible in Laravel/Symfony.
symfony
The query string of a URL is not considered when matching routes. In this example, URLs like /blog?foo=bar and /blog?foo=bar&bar=foo will also match the blog_list route.
https://symfony.com/doc/6.0/routing.html
laravel afaik doesnt support that either
you are obviously free to just forward yourself
e.g. write one router that forwards to other controllers
symfony https://symfony.com/doc/6.1/controller/forwarding.html

Is there any way that we can loop a function in a controller for multiple data validation?

I'm having a problem related to multiple data validation and want to know if there is any solution for loop condition of a function in a controller.If any please provide the solution.
I had tried using for loop but that dosent seem to work on Laravel Controllers
by default laravel supports multiple rules for validation, you have add | between the rules, like required|numeric|unique:posts. laravel will check the rules one after another.
Please add more details on your question and add your code.

Laravel RESTful routing

Consider the following 3 lines of code in a routes file:
Route::pattern('token', '[0-9a-z]+');
Route::get('user/reset/{token}', 'UserController#getReset');
Route::controller('user', 'UserController');
Are the pattern and get routes serving any purpose in this example? As I understand it, the RESTful controller route at the bottom will match any user/reset/{target} URL to the UserController getReset action, regardless of any token pattern supplied.
Is it possible to use a regex constraint on a route like this, where there is also a "catch-all" controller route?
The extra routes aren't needed in this example.
Right now, all the /user/reset requests are going to getReset. You could either send the constrained route to a different method, or neater, perform the validation in the controller to match the token and throw an exception if it doesn't match your constraints (or pass them off to your catch all idea).
Hope that helps.

Ajax results filtering and URL parameters

I am building a results filtering page using AJAX requests. I would like to reflect the filters in the URL. For example: for price_from I want to add ?price_from=VAL to the URL.
I have a backend that is capable of rendering the page with URL parameters.
After some googling I would a Backbone.router solution which has a hash fallback for the IE that does not support HTML5 history API.
I have a problem with setting a good philosophy of routes. I have a set of filtering parameters (price_from, price_to, color, ...) and I would like to attach each parameter to one route.
Is that possible to chain the routes to match for example: ?price_from=0&price_to=1&color=red? (the item order can change)
It means: call all the routes at the same time and keep the ie backwards compatibility?
Your best bet would be to have a query portion of the URL rather than using GET parameters to denote the search criteria. For example:
Push state: /search/query/price_from=0&price_to=1&color=red
Hash based: #search/query/price_from=0&price_to=1&color=red
Your backend would of course need to change a bit to be able to parse the new URL structure.

Asp.Net Web Api - Change parameter name

In my team we have coding rule that requires that every function's parameter starts with prefix, e.g. *p_someParam*.
With Web Api if we want to request a GET function that takes two parameters, we should add those parameters like "...?p_firstParam=value1&p_secondParam=value2".
Is there some way to use in requests more user-friendly names, like someParam without prefix, that will automatically map to parameters in controller's action? Maybe there is some attribute to rename action parameters? I couldn't find any similar example.
Every clue is appreciated.
I think you looking for URL rewriting, in that you need to map the urls to config or programmatic
http://www.codeproject.com/Articles/2538/URL-Rewriting-with-ASP-NET nice article to follow, its in ASP.Net,

Resources