So i want to use default api route that laravel provided which is
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Based on the documentation i made api_token column in the user table and generate random string everytime a user register to fill the column.
When i test the api using postman it return the user json. (I already include Accept and Authorization bearer header).
But when i tried to call the api through controller it always return null
This is my code
$token = 'abcde';
$request = Request::create('/api/user', 'GET', [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
]);
$response = json_decode(Route::dispatch($request)->getContent());
But it will return json if the route doesnt attach middleware(api:auth)
I also tried to use Guzzle and it give Curl 6 error unresolved host
Any suggestion? Thank You