<?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: Brian Dillingham</title>
    <description>The latest articles on DEV Community by Brian Dillingham (@dillinghamdev).</description>
    <link>https://dev.to/dillinghamdev</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%2F141834%2Fe3df3148-c888-4935-8bad-1b06059d65ab.jpeg</url>
      <title>DEV Community: Brian Dillingham</title>
      <link>https://dev.to/dillinghamdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dillinghamdev"/>
    <language>en</language>
    <item>
      <title>Jetstream / Inertia redirect login with axios &amp; intended</title>
      <dc:creator>Brian Dillingham</dc:creator>
      <pubDate>Thu, 14 Oct 2021 10:55:29 +0000</pubDate>
      <link>https://dev.to/dillinghamdev/jetstream-inertia-redirect-axios-intended-11en</link>
      <guid>https://dev.to/dillinghamdev/jetstream-inertia-redirect-axios-intended-11en</guid>
      <description>&lt;p&gt;If you have to use axios and need to catch 401 errors (unauthorized) and redirect to login but want to redirect back: simply route an inertia request to the current url and it will handle routing to login and set intended in the session&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="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;errors&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$inertia&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&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;



</description>
    </item>
    <item>
      <title>Laravel Assert Inertia Values</title>
      <dc:creator>Brian Dillingham</dc:creator>
      <pubDate>Tue, 27 Apr 2021 00:04:18 +0000</pubDate>
      <link>https://dev.to/dillinghamdev/assert-laravel-inertia-values-3oag</link>
      <guid>https://dev.to/dillinghamdev/assert-laravel-inertia-values-3oag</guid>
      <description>&lt;p&gt;After hunting around Google and Github without finding a clear way to assert the values returned from &lt;code&gt;Inertia::render&lt;/code&gt; the same way you can with a blade view, &lt;code&gt;assertViewHas&lt;/code&gt;, I realized Inertia is returning a &lt;code&gt;$page&lt;/code&gt; variable with the props. Because of this, we can drill down to the value we want to assert since &lt;code&gt;assertViewHas&lt;/code&gt; accepts dot notation.&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="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&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;create&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'/posts'&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;assertViewHas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'page.props.posts.data'&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="nv"&gt;$posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&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;Note: Im paginating $posts, otherwise &lt;code&gt;.data&lt;/code&gt; is not needed&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>inertia</category>
    </item>
    <item>
      <title>The 8th Missing Resource Route in the CRUD Pattern</title>
      <dc:creator>Brian Dillingham</dc:creator>
      <pubDate>Fri, 12 Mar 2021 02:24:07 +0000</pubDate>
      <link>https://dev.to/dillinghamdev/the-8th-missing-resource-route-in-the-crud-pattern-fgn</link>
      <guid>https://dev.to/dillinghamdev/the-8th-missing-resource-route-in-the-crud-pattern-fgn</guid>
      <description>&lt;p&gt;Conventions are patterns we or others have established as generally good ways of doing things. We save a lot of time when we reduce the amount of decisions we have to make and thought put into things by using conventions. &lt;/p&gt;

&lt;p&gt;I stumbled upon &lt;a href="https://laravel.com"&gt;Laravel&lt;/a&gt; early in my software career and every convention was better than what I was doing. And years later, those conventions still serve me well. Laravel was first to introduce me to the &lt;a href="https://laravel.com/docs/controllers#actions-handled-by-resource-controller"&gt;7 resourceful routes&lt;/a&gt; convention.&lt;/p&gt;

&lt;p&gt;If you're not familiar, this pattern is 7 endpoints you generally code for a "resource" to Create, Read, Update and Delete. Here is a table to illustrate a "Post" resource and the HTTP verbs following this convention:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Verb&lt;/th&gt;
&lt;th&gt;URI&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;index&lt;/td&gt;
&lt;td&gt;show list of posts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/create&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;create&lt;/td&gt;
&lt;td&gt;show create form&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;POST&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;store&lt;/td&gt;
&lt;td&gt;process create form&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show&lt;/td&gt;
&lt;td&gt;display single post&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}/edit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;edit&lt;/td&gt;
&lt;td&gt;show edit form&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PUT/PATCH&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;update&lt;/td&gt;
&lt;td&gt;process edit form&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DELETE&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;destroy&lt;/td&gt;
&lt;td&gt;process delete request&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Following this convention has saved me so much time. Naming and structuring things can be a huge time eater. If the "resource" doesn't fit 100% into that convention, I usually can break out a new resource and continue the CRUD convention. Adam Wathan gave &lt;a href="https://www.youtube.com/watch?v=MF0jFKvS4SI"&gt;a great talk&lt;/a&gt; about this in Laracon 2017.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;The problem is DELETE. Every app I work on I spend time thinking of confirmations when allowing users to delete things. Each app has had slightly different UI approaches which can be a time eater because design is very subjective. So I wanted to explore this because again.. conventions save us time and I'm feeling some friction without a standardized approach.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Missing Endpoint
&lt;/h3&gt;

&lt;p&gt;What I have come to think is that maybe there is a missing endpoint in this convention and adding one might be the answer. What if the destroy action had a GET endpoint which could be used to display a confirmation page, accept a password confirmation, retrieve data related to the delete etc&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Verb&lt;/th&gt;
&lt;th&gt;URI&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GET&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}/delete&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;remove&lt;/td&gt;
&lt;td&gt;show delete confirmation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DELETE&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/posts/{id}/delete&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;destroy&lt;/td&gt;
&lt;td&gt;process delete request&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;edit&lt;/code&gt; -&amp;gt; &lt;code&gt;update&lt;/code&gt; | &lt;code&gt;create&lt;/code&gt; -&amp;gt; &lt;code&gt;store&lt;/code&gt; | &lt;code&gt;remove&lt;/code&gt; -&amp;gt; &lt;code&gt;destroy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For such a small change, it really creates a positive impact. I have implemented this in a few projects and noticed the friction not only gone, but it cleans up my code quite a bit. Here are the benefits I noticed:&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Link to the delete route from anywhere within or outside the  codebase&lt;/li&gt;
&lt;li&gt;A dedicated endpoint if any data is needed to populate confirmation message: "you're about to delete 1,253 related records"&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  More thought
&lt;/h3&gt;

&lt;p&gt;Both the &lt;code&gt;store&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; actions, (the other 2 endpoints that affect change in the database) have a corresponding GET route before performing the actions. This makes sense because they need an endpoint to accept inputs. But for sensitive data, so does &lt;code&gt;destroy&lt;/code&gt;.. a password confirmation. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Not every convention is going to work for everything, including this one. I think this idea has some benefits, but it really just depends about your project. I wrote this to just share an idea incase others share in my experience and want another convention to consider.&lt;/p&gt;




&lt;p&gt;Let's connect on Twitter, I mostly tweet Laravel stuff.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/im_brian_d"&gt;https://twitter.com/im_brian_d&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Laravel Jetstream: From blade to using Inertia &amp; Vue</title>
      <dc:creator>Brian Dillingham</dc:creator>
      <pubDate>Wed, 10 Mar 2021 03:43:01 +0000</pubDate>
      <link>https://dev.to/dillinghamdev/setup-inertia-js-pages-with-vue-and-laravel-jetstream-4pee</link>
      <guid>https://dev.to/dillinghamdev/setup-inertia-js-pages-with-vue-and-laravel-jetstream-4pee</guid>
      <description>&lt;p&gt;Laravel Jetstream + Inertia is an amazing foundation for building modern apps using Vue (auth, basic ui kit) without the struggles of SPA. This article assumes you followed the installation steps on &lt;a href="https://jetstream.laravel.com/2.x/installation.html" rel="noopener noreferrer"&gt;Laravel Jetstream's website&lt;/a&gt; for Inertia and you are ready to jump in but you're a little new to Inertia or Vue.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I work with Inertia?
&lt;/h3&gt;

&lt;p&gt;Inertia may seem very different at first, but nothing actually changes with how you think about things like routes, controllers and views within Laravel. You still add a route to web.php, point it to a controller and return a view. &lt;/p&gt;

&lt;p&gt;The main difference is that you return &lt;code&gt;Inertia::render()&lt;/code&gt; from a controller. This response will ultimately render a Vue component and pass it data defined in our Laravel controllers.. solving a complexity of using Vue + Laravel.&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="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;'posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'PostsController@index'&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;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'posts.index'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Inertia&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Posts/Index'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'posts'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$posts&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;h3&gt;
  
  
  Where do I put views?
&lt;/h3&gt;

&lt;p&gt;There is a &lt;code&gt;resources/js/Pages&lt;/code&gt; folder created when you installed Jetstream. Add &lt;code&gt;Posts/Index.vue&lt;/code&gt; within that folder to handle &lt;code&gt;Inertia::render('Posts/Index')&lt;/code&gt;. Similar to &lt;code&gt;view('posts.index')&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Where are my changes when I refresh?
&lt;/h3&gt;

&lt;p&gt;Since we are using Vue, we need to compile our vue components / pages or the changes we make in .vue files will not show in the browser. It basically just means &lt;code&gt;npm install&lt;/code&gt; to install dependencies and &lt;code&gt;npm run watch&lt;/code&gt; to watch files for changes and re-compile. Luckily Laravel makes this user friendly. &lt;a href="https://laravel.com/docs/mix" rel="noopener noreferrer"&gt;docs&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I access the view data?
&lt;/h3&gt;

&lt;p&gt;The vue component will automatically receive the data we added to &lt;code&gt;Inertia::render()&lt;/code&gt; within our controller just like when we say &lt;code&gt;view()-&amp;gt;with()&lt;/code&gt;. The key differences are we need to add each variable as a property in &lt;code&gt;props&lt;/code&gt; so vue is aware and use &lt;a href="https://vuejs.org/v2/guide/syntax.html" rel="noopener noreferrer"&gt;vue's template&lt;/a&gt; syntax instead of Blade.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources/js/Pages/Posts/Index.vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;app-layout&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;#header&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"font-semibold text-xl text-gray-800 leading-tight"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                Posts
            &lt;span class="nt"&gt;&amp;lt;/h2&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;div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"max-w-7xl mx-auto py-10 sm:px-6 lg:px-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"post in posts"&lt;/span&gt; &lt;span class="na"&gt;:key=&lt;/span&gt;&lt;span class="s"&gt;"post.id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    {{ post.title }}
                &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/app-layout&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;import&lt;/span&gt; &lt;span class="nx"&gt;AppLayout&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/Layouts/AppLayout&lt;/span&gt;&lt;span class="dl"&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;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

    &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;AppLayout&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;ul&gt;
&lt;li&gt;What is the &lt;code&gt;@&lt;/code&gt; in the import? It's &lt;a href="https://laravel-news.com/laravel-mix-alias" rel="noopener noreferrer"&gt;an alias&lt;/a&gt; defined in webpack.mix.js&lt;/li&gt;
&lt;li&gt;What is #header? Shorthand for &lt;a href="https://vuejs.org/v2/guide/components-slots.html" rel="noopener noreferrer"&gt;Vue's component slot&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is &lt;code&gt;&amp;lt;app-layout&amp;gt;&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Jetstream comes with a lot of really useful vue components for things like form elements and modals, located in &lt;code&gt;resources/js/Jetstream&lt;/code&gt;, but &lt;code&gt;&amp;lt;app-layout&amp;gt;&lt;/code&gt; is in &lt;code&gt;resources/js/Layouts&lt;/code&gt; and is the main shell that renders this: &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd587paw2blb01fdezrnm.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd587paw2blb01fdezrnm.png" alt="Laravel Jetstream Vue Inertia"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adding your content within this vue component means you'll automatically have navigation in place and a nice starting point for your layout.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I link to my page?
&lt;/h3&gt;

&lt;p&gt;Jetstream installs &lt;a href="https://github.com/tightenco/ziggy" rel="noopener noreferrer"&gt;Ziggy&lt;/a&gt; to handle using named routes within Inertia / Vue. Using Ziggy's &lt;code&gt;route&lt;/code&gt; method &amp;amp; the &lt;code&gt;&amp;lt;inertia-link&amp;gt;&lt;/code&gt; &lt;a href="https://inertiajs.com/links" rel="noopener noreferrer"&gt;component&lt;/a&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;inertia-link&lt;/span&gt; &lt;span class="na"&gt;:href=&lt;/span&gt;&lt;span class="s"&gt;"route('posts.index')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Posts
&lt;span class="nt"&gt;&amp;lt;/inertia-link&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a link to the main navigation within the &lt;code&gt;&amp;lt;app-layout&amp;gt;&lt;/code&gt;, open the layout file within &lt;code&gt;resources/js/Layouts/App.vue&lt;/code&gt; and add a link:&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="c"&gt;&amp;lt;!-- Navigation Links --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hidden space-x-8 sm:-my-px sm:ml-10 sm:flex"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;jet-nav-link&lt;/span&gt; &lt;span class="na"&gt;:href=&lt;/span&gt;&lt;span class="s"&gt;"route('dashboard')"&lt;/span&gt; &lt;span class="na"&gt;:active=&lt;/span&gt;&lt;span class="s"&gt;"route().current('dashboard')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Dashboard
    &lt;span class="nt"&gt;&amp;lt;/jet-nav-link&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;jet-nav-link&lt;/span&gt; &lt;span class="na"&gt;:href=&lt;/span&gt;&lt;span class="s"&gt;"route('posts.index')"&lt;/span&gt; &lt;span class="na"&gt;:active=&lt;/span&gt;&lt;span class="s"&gt;"route().current('posts.index')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Posts
    &lt;span class="nt"&gt;&amp;lt;/jet-nav-link&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;code&gt;&amp;lt;jet-nav-link&amp;gt;&lt;/code&gt; is a component in &lt;code&gt;resources/js/Jetstream&lt;/code&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I submit forms?
&lt;/h3&gt;

&lt;p&gt;Inertia provides &lt;a href="https://inertiajs.com/forms" rel="noopener noreferrer"&gt;a really helpful way&lt;/a&gt; of using ajax to submit forms. First, use &lt;code&gt;v-model&lt;/code&gt; to &lt;a href="https://vuejs.org/v2/guide/forms.html" rel="noopener noreferrer"&gt;connect your inputs&lt;/a&gt; to the &lt;a href="https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties" rel="noopener noreferrer"&gt;vue state&lt;/a&gt; defined in the &lt;code&gt;data()&lt;/code&gt; section of your vue component and &lt;a href="https://vuejs.org/v2/guide/events.html#Method-Event-Handlers" rel="noopener noreferrer"&gt;call a method&lt;/a&gt; using the &lt;code&gt;@submit&lt;/code&gt; event handler.&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;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit.prevent=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Title:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"form.title"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Body:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"body"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"form.body"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&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="nf"&gt;data&lt;/span&gt;&lt;span class="p"&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;form&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$inertia&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;form&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="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;h3&gt;
  
  
  How does Inertia render Vue?
&lt;/h3&gt;

&lt;p&gt;Laravel Jetstream sets the root view to app.blade.php in &lt;code&gt;app/Http/Middleware/HandleInertiaRequests&lt;/code&gt; which is rendering:&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;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"font-sans antialiased"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   @inertia
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is outputting the root div Vue will attach to and passing it data:&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt; &lt;span class="na"&gt;data-page=&lt;/span&gt;&lt;span class="s"&gt;"{{ json_encode($page) }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How is resources/js/Pages defined?
&lt;/h3&gt;

&lt;p&gt;This mapping happens in &lt;code&gt;resources/app.js&lt;/code&gt;&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="nx"&gt;resolveComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`./Pages/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Hope you found that helpful. I plan to write more about Jetstream as I find it to be extremely powerful. If you have feedback, I'd love to hear it on twitter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/dillingham_dev" rel="noopener noreferrer"&gt;https://twitter.com/dillingham_dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>vue</category>
      <category>php</category>
    </item>
  </channel>
</rss>
