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

scott80109's avatar

Laravel Jetstream for API project?

I'm about to build my first Laravel project. It will be an API only app for now, but I will eventually build on a front-end web app. As I am creating the project, I'm wondering if I should create it with no starter kit and just add Sanctum? Or should I use the Jetstream starter kit with the future front-end web app in mind?

Here's a little more info on what I need to do:

  • Migrate a very large legacy PHP 5.6/ZendFramework 1 application to Laravel
  • Starting with creating an API app with Laravel 11
  • Migrating all back-end code over to Laravel 11 piece by piece, and the legacy app will use the API
  • Once nothing is left of the legacy app except for the front-end, I will build a new front-end into the Laravel app

If anyone has ever done something similar, or has any tips or advice, I would love to hear about it.

0 likes
1 reply
LaryAI's avatar
Level 58

When deciding whether to use Laravel Jetstream or just Sanctum for an API-only project that will eventually have a front-end, there are a few considerations to keep in mind:

  1. Immediate Needs: Since your immediate need is to create an API-only application, you might want to start with a minimal setup. Laravel Sanctum is a good choice for API token authentication and can be easily integrated into your project.

  2. Future Front-End: If you are certain that you will build a front-end web application in the future, using Jetstream might save you some setup time later. Jetstream provides a robust starting point with authentication, user management, and more, which can be beneficial when you transition to building the front-end.

  3. Complexity and Overhead: Jetstream comes with additional features and dependencies that you might not need immediately. If you prefer to keep your initial setup simple and lightweight, starting with Sanctum and adding Jetstream later when you need it might be a better approach.

Recommended Approach

Given your scenario, I would recommend starting with a minimal setup using Laravel Sanctum for the API. This allows you to focus on migrating your legacy application to Laravel without the additional overhead of Jetstream. Once you are ready to build the front-end, you can then integrate Jetstream or any other front-end framework as needed.

Steps to Set Up Laravel with Sanctum

  1. Create a new Laravel project:

    composer create-project laravel/laravel my-api-app
    
  2. Install Sanctum:

    composer require laravel/sanctum
    
  3. Publish the Sanctum configuration:

    php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
    
  4. Run the Sanctum migrations:

    php artisan migrate
    
  5. Configure Sanctum in config/sanctum.php: Ensure that the middleware is added to your api middleware group within your app/Http/Kernel.php file:

    'api' => [
        \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        'throttle:api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
    
  6. Add Sanctum's middleware to your api routes in routes/api.php:

    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Route;
    
    Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
        return $request->user();
    });
    
  7. Set up token-based authentication: You can create tokens for users like this:

    $user = User::find(1);
    $token = $user->createToken('token-name')->plainTextToken;
    
  8. Protect your routes: Use the auth:sanctum middleware to protect your routes:

    Route::middleware('auth:sanctum')->get('/protected-route', function () {
        return response()->json(['message' => 'This is a protected route']);
    });
    

Transitioning to Jetstream

When you are ready to build the front-end, you can install Jetstream and choose the stack (Livewire or Inertia) that best fits your needs:

  1. Install Jetstream:

    composer require laravel/jetstream
    
  2. Install Jetstream with your preferred stack: For Livewire:

    php artisan jetstream:install livewire
    

    For Inertia:

    php artisan jetstream:install inertia
    
  3. Run the Jetstream migrations:

    php artisan migrate
    
  4. Install and build your front-end assets:

    npm install && npm run dev
    

By following this approach, you can start with a minimal setup for your API and gradually add more features as you transition to building the front-end. This allows you to manage complexity and focus on the immediate task of migrating your legacy application.

Please or to participate in this conversation.