<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Cristian Pallarés</title>
    <description>The latest articles on Forem by Cristian Pallarés (@skyrpex).</description>
    <link>https://forem.com/skyrpex</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F823%2F1077520.jpeg</url>
      <title>Forem: Cristian Pallarés</title>
      <link>https://forem.com/skyrpex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/skyrpex"/>
    <language>en</language>
    <item>
      <title>LaravelNuxt under the hood</title>
      <dc:creator>Cristian Pallarés</dc:creator>
      <pubDate>Tue, 17 Jul 2018 18:08:42 +0000</pubDate>
      <link>https://forem.com/skyrpex/laravelnuxt-under-the-hood-36lp</link>
      <guid>https://forem.com/skyrpex/laravelnuxt-under-the-hood-36lp</guid>
      <description>&lt;p&gt;In this post we'll see how &lt;a href="https://github.com/skyrpex/laravel-nuxt"&gt;laravel-nuxt&lt;/a&gt; works. If you don't know what is it, you can check the introduction and tutorial&lt;br&gt;
&lt;a href="https://dev.to/skyrpex/create-a-spa-with-laravel-and-nuxt--54k"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Basically, there are two different modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development mode&lt;/li&gt;
&lt;li&gt;Production mode&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Development mode
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;laravel-nuxt dev&lt;/code&gt; command will launch two servers that interact with each other: Nuxt's and Laravel's dev servers.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Nuxt server
&lt;/h3&gt;

&lt;p&gt;Will be launched internally using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nuxt dev &lt;span class="nt"&gt;--spa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the server we'll be fetching with our browser. Serves multiple purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Listen to the port 8000 by default.&lt;/li&gt;
&lt;li&gt;Compile assets and enable &lt;a href="https://webpack.js.org/concepts/hot-module-replacement/"&gt;Hot Module Replacement&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Render the HTML page when accessing a special dev URL (which is &lt;code&gt;/__laravel_nuxt__&lt;/code&gt; by default).&lt;/li&gt;
&lt;li&gt;Proxy any other routes to the Laravel server (that aren't &lt;code&gt;/__laravel_nuxt__&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Proxying to Laravel is mandatory because we won't be handling headers or cookies using Nuxt.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Laravel server
&lt;/h3&gt;

&lt;p&gt;The Laravel server will be launched internally using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We aren't supposed to do any calls here. It will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Listen to the 8001 port by default.&lt;/li&gt;
&lt;li&gt;Serve your routes as usual (which should consist in API routes only).&lt;/li&gt;
&lt;li&gt;Serve a fallback route which will render the &lt;code&gt;/__laravel_nuxt__&lt;/code&gt; page whenever a non-AJAX call is made.

&lt;ul&gt;
&lt;li&gt;This is handled by the &lt;code&gt;Pallares\LaravelNuxt\Controllers\NuxtController::class&lt;/code&gt; controller.&lt;/li&gt;
&lt;li&gt;This should be your only web route.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the proxying from Nuxt to Laravel, we let our app to attach any headers and cookies (like &lt;code&gt;laravel_session&lt;/code&gt;) to the HTML rendered by Nuxt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production mode
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;laravel-nuxt build&lt;/code&gt; command will just execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nuxt build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It'll compile all your frontend assets to the &lt;code&gt;public/_nuxt&lt;/code&gt; directory, which will usually consist of some JS files and CSS files, along with a &lt;code&gt;index.html&lt;/code&gt; file which will be served by the &lt;code&gt;Pallares\LaravelNuxt\Controllers\NuxtController::class&lt;/code&gt; controller.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any non-AJAX request to the Laravel server (that doesn't match any existing route) will render your HTML page. As you may have noticed, you'll never get a 404 response from Laravel (but you may still render a 404 page using Nuxt).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The app will be deployment-ready after executing this command. You can also test it using &lt;code&gt;php artisan serve&lt;/code&gt; and opening &lt;code&gt;http://localhost:8000/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you still have any doubts, don't hesitate to write a question here! Regards.&lt;/p&gt;

</description>
      <category>spa</category>
      <category>api</category>
      <category>laravel</category>
      <category>nuxt</category>
    </item>
    <item>
      <title>Create a SPA with Laravel and Nuxt</title>
      <dc:creator>Cristian Pallarés</dc:creator>
      <pubDate>Tue, 13 Feb 2018 20:54:40 +0000</pubDate>
      <link>https://forem.com/skyrpex/create-a-spa-with-laravel-and-nuxt--54k</link>
      <guid>https://forem.com/skyrpex/create-a-spa-with-laravel-and-nuxt--54k</guid>
      <description>&lt;p&gt;In this tutorial we'll use &lt;a href="https://laravel.com/" rel="noopener noreferrer"&gt;Laravel&lt;/a&gt; as an API and &lt;a href="https://nuxtjs.org/" rel="noopener noreferrer"&gt;Nuxt&lt;/a&gt; as a Single Page Application. They can work together, but it's not an easy task at first. If you already tried, getting HMR to seamlessly work is a pain! For that reason I created &lt;a href="https://github.com/skyrpex/laravel-nuxt" rel="noopener noreferrer"&gt;laravel-nuxt&lt;/a&gt; and &lt;a href="https://github.com/skyrpex/laravel-nuxt-js" rel="noopener noreferrer"&gt;laravel-nuxt-js&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are more reasons to use these packages, such as when using &lt;a href="https://laravel.com/docs/5.5/passport" rel="noopener noreferrer"&gt;Laravel Passport&lt;/a&gt; and the &lt;code&gt;CreateFreshApiToken&lt;/code&gt;. The middleware will create an &lt;code&gt;api_token&lt;/code&gt; cookie on &lt;code&gt;web&lt;/code&gt; routes that use the &lt;code&gt;get&lt;/code&gt; http verb, and that's a problem if you're not serving your SPA from within Laravel.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Install Laravel
&lt;/h2&gt;

&lt;p&gt;Let's start with fresh new Laravel installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project laravel/laravel spa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go inside the &lt;code&gt;spa&lt;/code&gt; directory with your terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install laravel-nuxt (for PHP)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# cd spa&lt;/span&gt;
composer require pallares/laravel-nuxt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This package will be autodiscovered. If you're using old versions of Laravel, just add the service provider in &lt;code&gt;config/app.php&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="s1"&gt;'providers'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="c1"&gt;// ...&lt;/span&gt;
        &lt;span class="nc"&gt;Pallares\LaravelNuxt\LaravelNuxtServiceProvider&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a fallback route that will render the SPA page in &lt;code&gt;routes/web.php&lt;/code&gt; file. Be sure to remove the default route that comes with the framework:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;// Route::get('/', function () {&lt;/span&gt;
&lt;span class="c1"&gt;//     return view('welcome');&lt;/span&gt;
&lt;span class="c1"&gt;// });&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'{uri}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'\\'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pallares\LaravelNuxt\Controllers\NuxtController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'uri'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'.*'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your backend is ready to serve the compiled assets that Nuxt will generate for you. Every route that would return a 404 now will serve our SPA page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install laravel-nuxt (for JS)
&lt;/h2&gt;

&lt;p&gt;It's time to install the JS package. Replace your &lt;code&gt;package.json&lt;/code&gt; file with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"laravel-nuxt dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"laravel-nuxt build"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"laravel-nuxt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^1.0.0"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;laravel-nuxt&lt;/code&gt; package will install Nuxt for you, along with &lt;a href="https://github.com/vuejs/vue" rel="noopener noreferrer"&gt;Vue&lt;/a&gt;, &lt;a href="https://github.com/vuejs/vue-router" rel="noopener noreferrer"&gt;vue-router&lt;/a&gt;, &lt;a href="https://github.com/nuxt-community/axios-module" rel="noopener noreferrer"&gt;@nuxtjs/axios&lt;/a&gt;, etc. Let's create the &lt;code&gt;nuxt.config.js&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;laravelNuxt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;laravel-nuxt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;laravelNuxt&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// Options such as mode, srcDir and generate.dir are already handled for you.&lt;/span&gt;
  &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From now on, Nuxt will look for the source files in the &lt;code&gt;resources/nuxt&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Create a hello world route in &lt;code&gt;resources/nuxt/pages/index.vue&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello {{ name }}!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to &lt;a href="http://localhost:8000" rel="noopener noreferrer"&gt;http://localhost:8000&lt;/a&gt;. You should see this: &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pbrd.co%2Fimages%2FH7v0Mzl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pbrd.co%2Fimages%2FH7v0Mzl.jpg" alt="hello-world-picture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! Laravel artisan's server and Nuxt's dev server are up and working together transparently. Try editing your home page now, it's very enjoyable to see the live reload in action.&lt;/p&gt;

&lt;p&gt;Under the hood, Nuxt's dev server is proxying every call to the Laravel's server, including the SPA rendering. Since &lt;code&gt;@nuxtjs/axios&lt;/code&gt; module is included (and proxied, too), you can make API calls normally.&lt;/p&gt;

&lt;h1&gt;
  
  
  Calling the API from the SPA
&lt;/h1&gt;

&lt;p&gt;The SPA will surely need to call our API, so let's add a route to &lt;code&gt;routes/api.php&lt;/code&gt; to retrieve the user information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'me'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Let's return fake information.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'John Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, edit &lt;code&gt;resources/nuxt/pages/index.vue&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello {{ user.name }}!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// https://github.com/nuxt-community/axios-module&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;asyncData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;api/me&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! Your page should now look like this!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pbrd.co%2Fimages%2FH7v06bS.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.pbrd.co%2Fimages%2FH7v06bS.jpg" alt="api-call-picture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In order to keep the tutorial simple, we aren't using any kind of authentication here. Integrating Passport should be almost trivial here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Deployment
&lt;/h1&gt;

&lt;p&gt;If you want to deploy your application, just run &lt;code&gt;npm run build&lt;/code&gt;. The compiled assets will be placed in the &lt;code&gt;public/_nuxt&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;You can preview your final app with the well known artisan command &lt;code&gt;php artisan serve&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You may want to add the &lt;code&gt;.nuxt&lt;/code&gt; and &lt;code&gt;public/_nuxt&lt;/code&gt; directories to your &lt;code&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;This is my first tutorial. I hope everything is clear and concise! Please, don't hesitate to ask questions here or create issues in the laravel-nuxt repositories. Thanks!&lt;/p&gt;

</description>
      <category>spa</category>
      <category>api</category>
      <category>laravel</category>
      <category>nuxt</category>
    </item>
  </channel>
</rss>
