Capítulo 13 de 108

Installation: Laravel

Core Idea

The shadcn CLI does not scaffold a Laravel app itself; start with laravel new (React starter kit + Inertia), then run shadcn init either via a shadcn/create preset command or the CLI directly.

Key Concepts

  • Prerequisite: laravel new my-app choosing the React starter kit (React + Inertia), before touching shadcn.
  • Components path: unlike Next/Vite (@/components/ui/* under src or root), Laravel components land in resources/js/components/ui/.
  • Overwrite prompt: when running init on a fresh Laravel+Inertia app, choose "Yes" to overwrite components.json and components (Laravel's starter kit may already scaffold conflicting files).

Code Examples

laravel new my-app
cd my-app
npx shadcn@latest init --preset [CODE] --template laravel   # or: npx shadcn@latest init
npx shadcn@latest add switch
import { Switch } from "@/components/ui/switch"

const MyPage = () => {
  return (
    <div>
      <Switch />
    </div>
  )
}

export default MyPage
  • O que demonstra: import idêntico ao padrão @/components/ui/*, mesmo com o arquivo físico morando em resources/js/components/ui/.

Anti-patterns

  • Expecting shadcn init to create the Laravel project: it only configures shadcn/ui inside an already-scaffolded Laravel+React+Inertia app.

Key Takeaways

  1. Two-step process always: laravel new (React starter kit) first, shadcn init second.
  2. Only two setup paths documented for Laravel (no separate "existing project" manual guide as with Next/Vite/Astro), presumably because Inertia+React already configures Tailwind/aliases.
  3. Physical file location differs (resources/js/components/ui/) but the @/ import alias stays consistent with other frameworks.

Connects To

  • installation-next: general pattern reference for shadcn/create vs CLI paths.