Skip to content

Instantly share code, notes, and snippets.

@ceccode
Created November 17, 2015 14:59
Show Gist options
  • Select an option

  • Save ceccode/313e7148ab8dd00241ee to your computer and use it in GitHub Desktop.

Select an option

Save ceccode/313e7148ab8dd00241ee to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Contracts\Foundation\Application;
class ReplaceTestVars implements Middleware
{
/**
* The application implementation.
*
* @var Application
*/
protected $app;
/**
* Create a new filter instance.
*
* @param Application $app
*
* @return \App\Http\Middleware\ReplaceTestVars
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if ('testing' === $this->app->environment() && ($request->isMethod('post') || $request->isMethod('put')) ) {
$input = $request->all();
$input['_token'] = $request->session()->token();
$request->replace($input);
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment