Yes, perhaps you have two types of intermediaries: those that run before the request and those that run after the request, you can find additional information about this.
To create the middleware responsible for this, you can generate it with this command:
php artisan make:middleware ProcessJsonMiddleware
protected $routeMiddleware = [
'auth' => 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'process.json' => 'App\Http\Middleware\ProcessJsonMiddleware',
];
, :
<?php namespace App\Http\Middleware;
use Closure;
use Tokenizer;
class ProcessJsonMiddleware {
public function handle($request, Closure $next)
{
if ($request->isJson())
{
$json_array = $request->json()->all();
$our_last_element = array_pop($json_array);
$request->json()->replace($json_array);
}
return $next($request);
}
}
json, , json :
public function index(Request $request)
{
dd($request->json()->all());
}