m2sd / nuxt-laravel

Nuxt module for integration with the Laravel framework
MIT License
101 stars 11 forks source link

Add Laravel to Nuxt #6

Open bitfactory-sarah-tammenga opened 4 years ago

bitfactory-sarah-tammenga commented 4 years ago

Hi, So I have a Nuxt.js project and I want to add Laravel. I added npm install --save-dev @nuxtjs/axios @nuxtjs/proxy nuxt-laravel And I added 'nuxt-laravel' to modules as well, but I am not sure what the next steps are. When I do npm run dev I get a message that Laravel support is disabled.

mentAl-maZe commented 4 years ago

Hi @bitfactory-sarah-tammenga,

Let's clarify some things in advance:

PHP is a server side scripting language and, in production, will need to be set up properly through a web server and a process manager (e.g. nginx + php-fpm) Consequently this module does not provide any means to serve a production ready PHP server. Please plan accordingly


The module disables Laravel support if it is unable to find the artisan PHP executable, which is located at the root of a Laravel project folder. If you do not already have one please follow the following steps to create one (see https://laravel.com/docs/7.x/installation#installing-laravel):

  1. setup PHP and composer on your system (depending on which operating system you use this step may vary) Here are some resources to get you started:
  2. Globally install the laravel installer: composer require global laravel/installer
  3. Create a new laravel project: laravel new projectName Note: this will create a folder named projectName, containing a full laravel installation, under the current working directory (i.e. the folder form which the command was executed)

Once you have a laravel project setup you can direct this module to it's directory as follows:

In nuxt.config.js:

export default {
  // ...
  modules: [
    'nuxt-laravel'
    // ...
  ],
  // ...
  laravel: {
    // A relative path will be resolved relative to the current working directory (i.e. the directory you execute 'yarn dev' from
    root: 'relative/path/to/laravel/project/directory'
    // An absolute path (note the leading '/') will be used as is
   root: '/absolute/path/to/laravel/project/directory'
  }
}

After the root is set the module should work correctly.

mentAl-maZe commented 4 years ago

Also: Laravel will not support this module natively, in order for Laravel to proxy calls to NuxtJS's internal router you need to configure a route (see: https://github.com/m2sd/nuxt-laravel#forwarding-all-undefined-routes-to-nuxt and mind the router.base setting in your nuxt.config.js, as this must be the prefix for any route which proxies to nuxt)

Alternatively (if you want to start fresh): You can use the m2s/larave-nuxt plugin as descibed here: https://github.com/m2sd/nuxt-laravel#the-easy-way