Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martinszeltins's avatar

Sanctum - Route [login] not defined when uploading file (or it logs me out)

EDIT: Wait, I think I forgot to send the auth token in my request...

I'm getting this error when trying to upload a file:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in file /var/www/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 431

I am using Sanctum and this is how I make the request to the backend:

fetch('user-settings/profile-picture', {
    method: 'POST',
    body: formData,
})

Then on the backend I have this controller

class UserProfilePictureController extends Controller
{
    public function __construct() {
        $this->middleware('auth:sanctum');
    }

    public function store() {
        $this->uploadFile();
        User::find(auth()->id())->update([ 'profile_picture' => $filename ]);
    }

But this gives me that error: Route [login] not defined...

But when I add the Accept: application/json header then it simply logs me out and returns 401 Unauthorized

What is happening here?

0 likes
1 reply
martinszeltins's avatar
martinszeltins
OP
Best Answer
Level 14

Sorry, my bad, I forgot to send the auth token header.

Please or to participate in this conversation.