Laravel Sanctum login issue

I am using laravel sanctum. I have created a login API and I am getting this error when i am creating Token

ArgumentCountError: Too few arguments to function App\Models\User::createToken(), 0 passed in project\app\Http\Controllers\API\AuthController.php on line 27 and at least 1 expected in file D:\laragon\www\laravel-8-react-js\vendor\laravel\sanctum\src\HasApiTokens.php on line 44

can anyone help me? Thank You

Here is my Code 
public function login(Request $request)
    $validator = Validator::make($request->all(), [
        'email' => 'required|email',
        'password' => 'required',

    if ($validator->fails()) {
        return $this->handleError($validator->errors()->first());

    $credentials = $request->only(['email', 'password']);
    if ($user = auth()->guard()->attempt($credentials)) {
        $auth = auth()->user();
        $result['token'] = $auth->createToken()->plainTextToken;
        $result['user'] = $auth;
        $res = [
            'bool' => true,
            'result' => $result,
            'message' => "Login Successful",
        return response()->json($res, 200);
    return response()->json([
        'bool' => false,
        'message' => "Login Failed"

>Solution :

the createtoken method requires input parameters. depending on the initial conditions. this is in the error.
Like this createToken($request->token_name)
Or with abilities

createToken('token-name', ['server:update'])

See doc sanctum token

Leave a Reply