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

hasanhatem's avatar

which package should i use to build my API?

Hello guys,

I am working on laravel 8 project and i should provide all functions and build API for mobile application.

I need Authentication system to work on mobile application also.

So which API Package should i use: Passport OR Sanctum.

in the docs they mention in Sanctum intro:

Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs

so it's better to use Sanctum for Mobiles Application? please advice me before starting

0 likes
5 replies
MohamedTammam's avatar

If you're going to use it for both session based and token based authentication then Sanctum is a very good choice.

1 like
OussamaMater's avatar

@hasanhatem No for mobile apps you NEED to issue tokens, but for web applications sanctum uses Laravel's built-in cookie based session authentication services (so it uses the web guard instead of other API guards).

1 like
OussamaMater's avatar
Level 37

It really depends on what features you are going to build.

I personally don't see the need of passport unless 'OAuth2' is a requirement.

And it's recommended if this is your first time building a token-based API to use sanctum rather than passport.

Reference:

However, if you are attempting to authenticate a single-page application, mobile application, or issue API tokens, you should use Laravel Sanctum. Laravel Sanctum does not support OAuth2; however, it provides a much simpler API authentication development experience.

2 likes

Please or to participate in this conversation.