Is it possible to create a route, that on the same URL calls different actions in different controllers based on the Content-Type
header?
I do NOT need this for testing purposes. I need something to use in the api.php
file.
Is it possible to create a route, that on the same URL calls different actions in different controllers based on the Content-Type
header?
I do NOT need this for testing purposes. I need something to use in the api.php
file.
I was looking for this approach, finally i register my routes base on special header that i want to check it.
In my case, i want to use same URL base and action base same base on Content-Type
as you.
I take all my header in web.php
and you can use it in api.php
and check this to find out that Content-Type
is set or not as below:
$headers = apache_request_headers();
// check headers Content-Type is application json for any call base on json request
if(array_key_exists('Content-Type', $headers) && strtolower($headers['Content-Type']) == 'application/json'){
// register routes that need Content-Type header
Route::get('/dashboard', "AuthController@dashboardWithHeader");
}else{
// register route that dont need this special header
Route::get('/dashboard', "AuthController@dashboard");
}
by this approach if Content-Type
header is set, you related routes registerd and vise versa.