Skip to content

Instantly share code, notes, and snippets.

@MahdiY
Last active June 19, 2018 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MahdiY/47de071c66dc861cd05590c787282f9b to your computer and use it in GitHub Desktop.
Save MahdiY/47de071c66dc861cd05590c787282f9b to your computer and use it in GitHub Desktop.
Use raw data (json) in laravel
<?php
/**
* Developer : MahdiY
* Web Site : MahdiY.IR
* E-Mail : M@hdiY.IR
*/
namespace App\Http\Middleware;
use Closure;
class RawData
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$raw = json_decode($request->getContent(), true);
if (json_last_error() == JSON_ERROR_NONE) {
$request->replace($raw);
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment