Last active
June 19, 2018 21:47
-
-
Save MahdiY/47de071c66dc861cd05590c787282f9b to your computer and use it in GitHub Desktop.
Use raw data (json) in laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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