Reputation: 1
I'm receiving requests from new front end which encrypt all of the post parameters
the previous frontend didn't encrypt the post parameters
however the current backend also doesn't decrypt the post parameters received
how do i alter the whole request received so that i can put the decryption first when calling the
$request->get('param_name');
so that when the value of param_name gets into the variables to be used, it's already decrypted
because modifying the whole backend 1 by 1 is really inefficient
i've ever alter the trans() function, just go the file that handles it and alter it
but on request
what is the file?
Upvotes: 0
Views: 917
Reputation: 559
You need create middleware for you action.
php artisan make:middleware RequestDecryptMiddleware
In Kernel.php add:
<?php
// Kernel.php
protected $routeMiddleware = [
...
'decrypt' => \App\Http\Middleware\RequestDecryptMiddleware::class,
...
];
After it you can overide params in middleware:
public function handle($request, Closure $next)
{
if($request->has('encrypt_param')){
$request->merge(['encrypt_param' => decrypt_function($request->get('encrypt_param'))]);
}
return $next($request);
}
Then use it in you controller:
public function myAction(RequestDecryptMiddleware $request)...
Upvotes: 0
Reputation: 50797
You can use middleware.
php artisan make:middleware RequestInterceptorMiddleware
Then in the handle
method you can interrogate the request
and perform a .merge()
if($request->has('param_name')) {
$request->merge(['param_name' => decrypt($request->get('param_name'))]);
}
return $next($request);
And then make sure to add that middleware to your Kernel.php
in your corresponding route middleware declarations.
Upvotes: 2