Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): nextUI with laravel #4432

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/docs/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
"title": "Astro",
"keywords": "astro, nextui",
"path": "/docs/frameworks/astro.mdx"
},
{
"key": "laravel",
"title": "Laravel",
"keywords": "laravel, nextui",
"path": "/docs/frameworks/laravel.mdx",
"newPost": true
}
]
},
Expand Down Expand Up @@ -515,4 +522,4 @@
]
}
]
}
}
238 changes: 238 additions & 0 deletions apps/docs/content/docs/frameworks/laravel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
---
title: Laravel
description: How to use NextUI with Laravel
---

# Laravel

Requirements:

- [Laravel 11](https://laravel.com/)
- [PHP v8.2](https://www.php.net/)
- [React 18](https://reactjs.org/) or later
- [Tailwind CSS 3.4](https://tailwindcss.com/docs/guides/vite#react) or later
- [Framer Motion 11.9](https://www.framer.com/motion/) or later
Comment on lines +8 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Consider broadening version support in requirements

Based on the verification:

  • Laravel 10.x requires PHP ^8.1
  • Laravel 11.x requires PHP ^8.2
  • Laravel 10 is the current LTS version (supported until February 2025)

Recommend updating the requirements section to:

Requirements:

- [Laravel 10](https://laravel.com/) or later
- [PHP v8.1](https://www.php.net/) or later
- [React 18](https://reactjs.org/) or later
- [Tailwind CSS 3.4](https://tailwindcss.com/docs/guides/vite#react) or later
- [Framer Motion 11.9](https://www.framer.com/motion/) or later

This change would:

  • Include the current LTS version of Laravel
  • Support a broader range of PHP versions
  • Allow more users to adopt NextUI while maintaining compatibility
🔗 Analysis chain

Consider broadening version support in requirements

The current requirements might be too restrictive:

  • Laravel 11 was just released (March 2024), consider supporting Laravel 10 LTS
  • PHP 8.2 is not the minimum requirement for Laravel, consider supporting PHP 8.1

Let me verify the minimum supported versions:


Let me verify Laravel's version support further:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Laravel's composer.json for PHP version requirements
curl -s https://raw.githubusercontent.com/laravel/laravel/10.x/composer.json | jq '.require.php'

Length of output: 103


Script:

#!/bin/bash
# Check Laravel 11's composer.json for PHP version requirements
curl -s https://raw.githubusercontent.com/laravel/laravel/11.x/composer.json | jq '.require.php'

# Check if there are any other Laravel version references in the codebase
rg -i "laravel.*version|laravel.*requirement" --type mdx

Length of output: 190


------

<CarbonAd/>

To use NextUI in your Laravel project, you need to follow the following steps:

### Using NextUI + Laravel template

If you are starting a new project, you can run one of the following commands to create a Laravel project pre-configured with NextUI:

<PackageManagers
commands={{
npm: 'npx create-laravel@latest --template https://github.com/nextui-org/laravel-template',
yarn: 'yarn create laravel --template https://github.com/nextui-org/laravel-template',
pnpm: 'pnpm create laravel --template https://github.com/nextui-org/laravel-template',
bun: 'bunx create-laravel@latest --template https://github.com/nextui-org/laravel-template',
}}
/>
Comment on lines +26 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Template repository URL is invalid

The commands reference a template repository at https://github.com/nextui-org/laravel-template which does not exist. This will cause the installation commands to fail.

  • apps/docs/content/docs/frameworks/laravel.mdx: Update the template URL to point to a valid repository or remove the template parameter if a default template should be used instead.
🔗 Analysis chain

Template repository URL appears to be missing

The commands reference a template repository at https://github.com/nextui-org/laravel-template which seems to be unavailable.

Let me verify the repository existence:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the template repository exists
gh repo view nextui-org/laravel-template 2>/dev/null || echo "Repository not found"

Length of output: 93


### Automatic Installation

You can add individual components using the CLI. For example, to add a button component:

```codeBlock bash
nextui add button
```

This command adds the Button component to your project and manages all related dependencies.

You can also add multiple components at once:

```codeBlock bash
nextui add button input
```

Or you can add the main library `@nextui-org/react` by running the following command:

```codeBlock bash
nextui add --all
```

If you leave out the component name, the CLI will prompt you to select the components you want to add.

```codeBlock bash
? Which components would you like to add? › - Space to select. Return to submit
Instructions:
↑/↓: Highlight option
←/→/[space]: Toggle selection
[a,b,c]/delete: Filter choices
enter/return: Complete answer

Filtered results for: Enter something to filter

◯ accordion
◯ autocomplete
◯ avatar
◯ badge
◯ breadcrumbs
◉ button
◯ card
◯ checkbox
◯ chip
◯ code
```

Comment on lines +35 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add CLI installation instructions

The section uses nextui CLI commands but doesn't explain:

  • How to install the CLI tool
  • Where these commands should be run (project root?)
  • Whether this is a global or project-local tool

Consider adding a prerequisite step explaining how to install and configure the CLI tool.

🧰 Tools
🪛 LanguageTool

[style] ~57-~57: To strengthen your wording, consider replacing the phrasal verb “leave out”.
Context: ...Block bash nextui add --all ``` If you leave out the component name, the CLI will prompt...

(OMIT_EXCLUDE)

You still need to add the provider to your app manually (we are working on automating this step).

```jsx {3,7,9}
// app/providers.tsx

import {NextUIProvider} from '@nextui-org/react'

export function Providers({children}: { children: React.ReactNode }) {
return (
<NextUIProvider>
{children}
</NextUIProvider>
)
}
```

<Spacer y={4} />

```jsx {8,23,25}
// app.tsx or app.jsx
import '../css/app.css';
import './bootstrap';

import { createInertiaApp } from '@inertiajs/react';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { createRoot } from 'react-dom/client';
import {NextUIProvider} from "@nextui-org/react";

const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) =>
resolvePageComponent(
`./Pages/${name}.tsx`,
import.meta.glob('./Pages/**/*.tsx'),
),
setup({ el, App, props }) {
const root = createRoot(el);

root.render(
<NextUIProvider>
<App {...props} />
</NextUIProvider>
);
},
progress: {
color: '#4B5563',
},
});
```

### Manual Installation

<Steps>

### Add dependencies

In your Laravel project, run one of the following command to install NextUI:

<PackageManagers
commands={{
npm: 'npm i @nextui-org/react framer-motion',
yarn: 'yarn add @nextui-org/react framer-motion',
pnpm: 'pnpm add @nextui-org/react framer-motion',
bun: "bun add @nextui-org/react framer-motion"
}}
/>

### Hoisted Dependencies Setup

<Blockquote color="primary">
**Note**: This step is only for those who use `pnpm` to install. If you install NextUI using other package managers, you may skip this step.
</Blockquote>

If you are using pnpm, you need to add the following line to your `.npmrc` file to hoist our packages to the root `node_modules`.

```bash
public-hoist-pattern[]=*@nextui-org/*
```

After modifying the `.npmrc` file, you need to run `pnpm install` again to ensure that the dependencies are installed correctly.

### Tailwind CSS Setup

NextUI is built on top of Tailwind CSS, so you need to install Tailwind CSS first. You can follow the official
[installation guide](https://tailwindcss.com/docs/guides/vite#react) to install Tailwind CSS. Then you need to add
the following code to your `tailwind.config.js` file:

<Blockquote color="primary">
**Note**: If you are using pnpm and monorepo architecture, please make sure you are pointing to the ROOT `node_modules`
</Blockquote>

```js {2,8,13-14}
// tailwind.config.js
const { nextui } = require("@nextui-org/react");

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
// ...
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {},
},
darkMode: "class",
plugins: [nextui()]
}
```

### Provider Setup

After installing NextUI, you need to set up the `NextUIProvider` at the `root` of your application.

Go to the src directory and inside `app.jsx` or `app.tsx`, wrap `NextUIProvider` around App:

```jsx {8,23,25}
// app.tsx or app.jsx
import '../css/app.css';
import './bootstrap';

import { createInertiaApp } from '@inertiajs/react';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { createRoot } from 'react-dom/client';
import {NextUIProvider} from "@nextui-org/react";

const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) =>
resolvePageComponent(
`./Pages/${name}.tsx`,
import.meta.glob('./Pages/**/*.tsx'),
),
setup({ el, App, props }) {
const root = createRoot(el);

root.render(
<NextUIProvider>
<App {...props} />
</NextUIProvider>
);
},
progress: {
color: '#4B5563',
},
});
```

</Steps>

<Blockquote
color="warning"
>
Version 2 is only compatible with React 18 or later. If you are using React 17 or earlier, please use <Link href="https://v1.nextui.org/docs/getting-started" isExternal>version 1 of NextUI</Link>.
</Blockquote>
Loading