5 days ago

Fetch API and Laravel

Posted 5 days ago by russellwwest

Hey, I'm having an issue where I am using fetch within a Vue app to call my Laravel API. However, my request object in Laravel is empty:

vue api call:

const requestOptions = {
          method: 'POST',
          headers: requestHeader(false),
          /* eslint-disable-next-line */
          body: JSON.stringify({ "email": '[email protected]', "password": 'password' })

        return fetch(`${baseUrl}/auth/authenticate`, requestOptions)

Laravel Controller:

public function authenticate(Request $request) : JsonResponse
        return response()->json(['message' => $request], 422);

The $request object is empty.

if I do this. then I see the data:

$data = json_decode($request->getContent(), true);

What am I doing wrong with the fetch api? It worked fine with axios Thanks,

Please sign in or create an account to participate in this conversation.