why request as a child of request?
Jun 23, 2018
5
Level 2
Custom request data not available in Controller constructor
I'm not managing to get data that I add to the Request, in my custom middleware, in the constructor of my Controller.
My Route:
Route::group(['middleware' => ['auth', 'checkIt']], function () {
Route::get('/items', 'ItemController@index');
});
My 'checkIt' middleware (the handle method):
public function handle(Request $request, Closure $next) {
$request->merge(['custom_data' => 'hello']);
return $next($request);
}
My Controller:
class ItemController extends Controller
{
public function __construct(Request $request) {
echo $request->get('custom_data'); // nothing
}
public function index(Request $request) {
echo $request->get('custom_data'); // outputs 'hello'
}
}
How can I get my 'custom_data' in the constructor?
Thanks
Please or to participate in this conversation.