# Laravel

Organize Laravel applications and Composer packages in Nx.


Keep PHP and Composer in charge of your Laravel application while using Nx to discover projects and run their tasks. Each application keeps its own environment, Composer manifest, and lockfile.

## Add to your workspace

Check the [Node.js and Nx requirements](/docs/workflows/requirements#platform-plugins) for this plugin before installing.

Install `@megamono/nx-laravel` as a development dependency using your workspace's package manager. Merge this entry into the existing `plugins` list in `nx.json`:

```json
{
  "plugins": [
    "@megamono/nx-laravel"
  ]
}
```

Run `npm exec -- nx show projects` to find your project, then `npm exec -- nx show project <project>` to see its tasks. Replace `<project>` with the name from the list.

## Create an application

```sh
npm exec -- nx generate @megamono/nx-laravel:application --name=portal --dry-run
```

After reviewing the preview, repeat without `--dry-run`. Generation prepares the Nx configuration. Run `npm exec -- nx run portal:setup` to fetch the Laravel skeleton, then review it before running `portal:composer-install`.

Create the app’s `.env` from `.env.example`, configure its URL and database, generate its Laravel application key, and install frontend dependencies using the app’s package manager. Database migrations are a separate step.

## Existing applications and Herd

Register the plugin to discover existing Composer packages and Laravel apps without generating over them. Install PHP and Composer first. For Herd, select `runtime: "herd"`; the generator also supports `herdDomain` and `phpVersion`. Run the explicit Herd link/isolation tasks when you want to configure that app.

See [Laravel application options](/docs/generators/nx-laravel-application) and [setup options](/docs/actions/nx-laravel-setup).
