Get Bearer Token from Authorization header

The bearerToken() function is very handy when you are working with apis & want to access the token from Authorization header.

1// Don't parse API headers manually like this:
2$tokenWithBearer = $request->header('Authorization');
3$token = substr($tokenWithBearer, 7);
4 
5//Do this instead:
6$token = $request->bearerToken();

Tip given by @iamharis010

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord