Docs
Laravel

Laravel

为 Laravel 安装并配置 shadcn/ui

创建项目

¥Create project

首先使用 laravel 安装程序 laravel new my-app 创建包含 Inertia 和 React 的新 Laravel 项目:

¥Start by creating a new Laravel project with Inertia and React using the laravel installer laravel new my-app:

laravel new my-app --react

添加组件

¥Add Components

你现在可以开始向你的项目添加组件。

¥You can now start adding components to your project.

pnpm dlx shadcn@latest add switch

上述命令会将 Switch 组件添加到 resources/js/components/ui/switch.tsx。然后你可以像这样导入它:

¥The command above will add the Switch component to resources/js/components/ui/switch.tsx. You can then import it like this:

import { Switch } from "@/components/ui/switch"
 
const MyPage = () => {
  return (
    <div>
      <Switch />
    </div>
  )
}
 
export default MyPage