<?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>DEV Community: 5ᗩᒪEᗪ 🦇</title>
    <description>The latest articles on DEV Community by 5ᗩᒪEᗪ 🦇 (@5aled_amoudi).</description>
    <link>https://dev.to/5aled_amoudi</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%2F887576%2F0fd44a66-8d1a-434e-a0db-393d11cdc448.jpg</url>
      <title>DEV Community: 5ᗩᒪEᗪ 🦇</title>
      <link>https://dev.to/5aled_amoudi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/5aled_amoudi"/>
    <language>en</language>
    <item>
      <title>How to use vue inertia in laravel project ?</title>
      <dc:creator>5ᗩᒪEᗪ 🦇</dc:creator>
      <pubDate>Tue, 05 Jul 2022 15:46:00 +0000</pubDate>
      <link>https://dev.to/5aled_amoudi/how-to-set-up-vue-inertia-in-laravel-project--b11</link>
      <guid>https://dev.to/5aled_amoudi/how-to-set-up-vue-inertia-in-laravel-project--b11</guid>
      <description>&lt;p&gt;&lt;a href="https://inertiajs.com/"&gt;Inertia &lt;/a&gt;is a small library that allows you to Build single-page apps, without building an API.&lt;/p&gt;

&lt;p&gt;First, use this command to create a laravel project:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer create-project --prefer-dist laravel/laravel inertia-app&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;OR you can define the laravel version you need, here for example i will use laravel 8 by running this command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer create-project --prefer-dist laravel/laravel:8.6.11 inertia-app&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Sitting up the inertia is divided into two stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;server-side&lt;/li&gt;
&lt;li&gt;client-side&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1- Server Side&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After creating laravel project you need to install inertia using this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require inertiajs/inertia-laravel&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and now, create a layout file in recourses\view\app.blade.php and add this into this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta charset=”utf-8" /&amp;gt;
&amp;lt;meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0" /&amp;gt;
&amp;lt;link href=”{{ mix(‘/css/app.css’) }}” rel=”stylesheet” /&amp;gt;
&amp;lt;script src=”{{ mix(‘/js/app.js’) }}” defer&amp;gt;&amp;lt;/script&amp;gt;
@inertiaHead
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
@inertia
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that you need to create inertia middleware using this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan inertia:middleware&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and don't forget to register the middleware in the App\Http\Kernel by adding this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;‘web’ =&amp;gt; [
// …
\App\Http\Middleware\HandleInertiaRequests::class,
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;2- &lt;strong&gt;Client-Side&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, install the dependencies by this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @inertiajs/inertia @inertiajs/inertia-vue3&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Second install vue.js:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install vue@next&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;[optional — recommended] if you use vue 3 and you need to use single-file component (SFC) which allows you to use &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;scripts&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;styles&amp;gt;&lt;/code&gt; on one page, you need to run this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -D @vue/compiler-sfc&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now in the resources\js\app.js file add this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createApp, h } from ‘vue’
import { createInertiaApp } from ‘@inertiajs/inertia-vue3’
createInertiaApp({
resolve: name =&amp;gt; require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () =&amp;gt; h(App, props) })
.use(plugin)
.mount(el)
},
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also don’t forget to create a Pages folder inside resources\js\, this Page folder will be used to create .vue files inside it.&lt;/p&gt;

&lt;p&gt;After that you need to update to code in (webpack.mix.js) by adding ( .vue(3) &amp;amp; .version() ), so it will be like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mix.js(‘resources/js/app.js’, ‘public/js’)
.vue(3)
.postCss(‘resources/css/app.css’, ‘public/css’, [
//
])
.version();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now install any remaining dependencies by running:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;then, to pull in any required dependencies you have run this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx mix&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;you may be asked to run npx mix again&lt;/p&gt;

&lt;p&gt;Now, an Error may occur when you run npx mix that asks you to Use  — location=global instead&lt;/p&gt;

&lt;p&gt;in this case, run this command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i vue-loader&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now run npx mix again:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx mix&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;That were the steps of setting up vue inertia in laravel project, I hope it was helpful 🥰.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>inertia</category>
      <category>vueinertia</category>
    </item>
  </channel>
</rss>
