failed authentication for laravel api code example

Example 1: laravel get authorization bearer token

//get Authorization Bearer Token value
$token = $request->bearerToken();

Example 2: signup API in laravel

/**
 * API Register
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */
public function register(Request $request)
{
    $rules = [
        'name' => 'unique:users|required',
        'email'    => 'unique:users|required',
        'password' => 'required',
    ];

    $input     = $request->only('name', 'email','password');
    $validator = Validator::make($input, $rules);

    if ($validator->fails()) {
        return response()->json(['success' => false, 'error' => $validator->messages()]);
    }
    $name = $request->name;
    $email    = $request->email;
    $password = $request->password;
    $user     = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);

}

Tags:

Php Example