<?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: Nathan Heffley</title>
    <description>The latest articles on DEV Community by Nathan Heffley (@nathanheffley).</description>
    <link>https://dev.to/nathanheffley</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%2F33385%2F6ca73bd1-71fd-4f69-b61d-ff334cd166c1.jpg</url>
      <title>DEV Community: Nathan Heffley</title>
      <link>https://dev.to/nathanheffley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nathanheffley"/>
    <language>en</language>
    <item>
      <title>Finding Joy While Losing Use of My Hands</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Fri, 11 Mar 2022 13:45:57 +0000</pubDate>
      <link>https://dev.to/nathanheffley/finding-joy-while-losing-use-of-my-hands-260h</link>
      <guid>https://dev.to/nathanheffley/finding-joy-while-losing-use-of-my-hands-260h</guid>
      <description>&lt;p&gt;Over the past year, especially the last 6 months, I have rapidly lost the ability to use my hands for precise, repetitive actions. Using a keyboard and mouse has become especially difficult. I've had minor pain for several years, but a standing desk, wrist braces, or a vertical mouse would fix the issue for a while. Finally learning how to type on a Colemak keyboard layout helped a bit more, but it wasn't enough.&lt;/p&gt;

&lt;p&gt;It started to become a serious conundrum seeing as how typing on a keyboard is my livelihood. Even beyond work, programming is my favorite hobby. The physical act of typing was a big part of that. The keyboard was my instrument.&lt;/p&gt;

&lt;p&gt;I needed a way to continue programming so I could keep working at the very least. A more ergonomic keyboard was the first idea, but I knew it would be a temporary fix at best. While searching for alternative input methods I somehow stumbled upon a talk called &lt;a href="https://youtu.be/Mz3JeYfBTcY" rel="noopener noreferrer"&gt;Perl Out Loud&lt;/a&gt;. The speaker, Emily Shea, did a fantastic job demonstrating how powerful voice controls could be. Thanks to her &lt;a href="https://whalequench.club/blog/2019/09/03/learning-to-speak-code.html" rel="noopener noreferrer"&gt;guide to voice driven development&lt;/a&gt; I was able to quickly get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overcoming the Loss
&lt;/h2&gt;

&lt;p&gt;The software I had found is called &lt;a href="https://talonvoice.com/" rel="noopener noreferrer"&gt;Talon&lt;/a&gt;. It comes with a robust voice detection model and total freedom in how you use it. It's not open source but the stable version is free for anyone to use, and the developer works on it full-time. Because it doesn't come with any commands out of the box, though, it requires some diving in to the Talon community. The Slack group is full of friendly and helpful folk so any issue you run into is quickly overcome. There's always someone sharing new ideas and tricks to help make using a computer easier. Even though Talon itself isn't open source, there are tons of additional tools, scripts, wikis, and setups that the community actively maintains as open source projects. Finding a community full of people, where a lot of them are going through the same thing as me or otherwise have difficulty in using a keyboard or mouse, has been crucial in not giving up because of the pain.&lt;/p&gt;

&lt;p&gt;Thankfully, the initial learning curve was such that I started using Talon for work within a week. I wasn't nearly as fast as when I used a keyboard, but without any pain I could get into a better flow state for longer periods of time; so it evened out quickly. While I wasn't worried that I'd have to leave my job anymore, I still wasn't enjoying my new setup. I had to completely remove the keyboard from my desk so that I'd stop using it to make a small correction or press a keyboard shortcut that I hadn't bound to a voice command yet. It was depressing enough that I gave up any non-work related programming despite how much I had enjoyed it a few months earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the Joy
&lt;/h2&gt;

&lt;p&gt;After two months or so I was getting pretty frustrated. Going back to using the keyboard was out of the question, so I pressed on, but not happily. I needed to look for some more advanced tooling to improve my productivity and reduce voice strain. The Talon community came to the rescue with a fantastically innovative VS Code plugin: &lt;a href="https://github.com/cursorless-dev/cursorless-vscode" rel="noopener noreferrer"&gt;Cursorless&lt;/a&gt;. Instead of moving a cursor around with vim-like bindings, I could use short identifiers to target very specific bits of code and manipulate them quickly.&lt;/p&gt;

&lt;p&gt;After using it for a few weeks my productivity had skyrocketed, and with it my enthusiasm for programming again. It brought back a feeling of mastery that I had lost when I set aside my keyboard.&lt;/p&gt;

&lt;p&gt;I've pulled the keyboard back out for things like video calls so that people don't think I'm trying to talk if I need to type a little bit during the meeting, but I make sure not to use it when I can use Talon instead. I'm still trying to kick my habit of using the mouse; unfortunately there's nothing quite as seamless as Cursorless for the mouse yet. My hands still hurt some days but now I can continue enjoying programming, and some days are even good enough that I can hold a video game controller without pain afterwards.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future
&lt;/h2&gt;

&lt;p&gt;When I first started using Talon it was supposed to be a temporary thing. I'll use it for a while, let my hands heal, and then go back to the keyboard. It was always a pipe dream if I'm being honest. I'm not sure exactly what happened to my hands 6 months ago to cause so much more pain than usual, but I do know this disability is unlikely to go away enough to use a keyboard and mouse full-time again.&lt;/p&gt;

&lt;p&gt;The one thing that I regret from before all this happened is not being more conscious of really learning how to make accessible websites. I'd watch for the easy wins like making sure colors had contrast and that elements were semantic, but it doesn't take long to learn how hard your projects are to use once you start needing accessibility tools yourself. I've since started learning as much as I can about building accessible websites, hopefully one of these days I understand it better.&lt;/p&gt;

&lt;p&gt;So for now I'm enjoying this new form of programming. I joke that I don't need a rubber duck anymore because I'm talking through my code constantly. The ability to put my code up on the TV and pace the room or sit on the couch and code has been a great alternative to being stuck at my desk all day.&lt;/p&gt;

&lt;p&gt;Cheers to many more days of coding!&lt;/p&gt;




&lt;p&gt;Let me know in the comments if you'd be interested in a series of posts discussing the more technical aspects of how I use Talon and Cursorless.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>opensource</category>
      <category>productivity</category>
      <category>talonvoice</category>
    </item>
    <item>
      <title>Can Developers Help #BlackLivesMatter?</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Sun, 07 Jun 2020 16:23:16 +0000</pubDate>
      <link>https://dev.to/nathanheffley/can-developers-help-blacklivesmatter-1h8c</link>
      <guid>https://dev.to/nathanheffley/can-developers-help-blacklivesmatter-1h8c</guid>
      <description>&lt;p&gt;Are there any open-source projects that need contributors or other ways that we as developers could use our unique skills to help improve racial equality?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Beautiful, Blocky Slack Messages</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Tue, 19 Mar 2019 15:42:34 +0000</pubDate>
      <link>https://dev.to/nathanheffley/beautiful-blocky-slack-messages-38aa</link>
      <guid>https://dev.to/nathanheffley/beautiful-blocky-slack-messages-38aa</guid>
      <description>&lt;p&gt;Recently Slack released a new message format that apps can take advantage of called &lt;a href="https://api.slack.com/block-kit" rel="noopener noreferrer"&gt;Block Kit&lt;/a&gt;. This new format allows apps and other software to send very rich messages through API calls or webhooks.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbj44iaf02n5q7ahrsh1.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%2Fwbj44iaf02n5q7ahrsh1.png" alt="A Slack message styled to look like a search result displaying three hotels"&gt;&lt;/a&gt;&lt;/p&gt;
An example of hotel search results as a message, one of Slack's official Block Kit example templates.



&lt;p&gt;If you're interested in sending messages like this, you'll first have to set up a Slack app. You'll need to have an account and workspace you can use for developing an app. Once you have that all lined up, you'll need to visit &lt;a href="https://api.slack.com/apps" rel="noopener noreferrer"&gt;https://api.slack.com/apps&lt;/a&gt; and press the "Create New App" button.&lt;/p&gt;

&lt;p&gt;Name it whatever you want and select the workspace you'll use for testing. The quickest way to start sending messages is to set up a webhook, so click on "Incoming Webhooks" in the sidebar menu and toggle the switch to activate incoming webhooks.&lt;/p&gt;

&lt;p&gt;Now at the bottom of the page you should see a button to add a new webhook to your workspace. Clicking on that will prompt you to select a channel and authorize the app. Since you should be able to trust that you won't abuse your own app, go ahead and pick whatever channel you want to send your test messages to and authorize yourself.&lt;/p&gt;

&lt;p&gt;You'll be redirected back to the previous page, but now you'll see a webhook for the channel you just selected. Copy that URL because we're going to use it now to send a message!&lt;/p&gt;

&lt;p&gt;To make sure your webhook is working, you can send yourself a simple message with the following curl command, just make sure to replace the webhook URL with the one you just copied.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/YOUR/WEBHOOK/HERE


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

&lt;/div&gt;
&lt;p&gt;Now, to send a block message, things start to get a little bit crazy. For the sake of simplicity we'll send a full block message with a curl command, but just know that this is a very simple message and I do not condone using curl as your main form of posting Slack messages.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl -X POST -H 'Content-type: application/json' --data '{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "*&amp;lt;fakeLink.toUserProfiles.com|Iris / Zelda 1-1&amp;gt;*\nTuesday, January 21 4:00-4:30pm\nBuilding 2 - Havarti Cheese (3)\n2 guests"
            },
            "accessory": {
                "type": "image",
                "image_url": "https://api.slack.com/img/blocks/bkb_template_images/notifications.png",
                "alt_text": "calendar thumbnail"
            }
        }
    ]
}' https://hooks.slack.com/services/YOUR/WEBHOOK/HERE


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

&lt;/div&gt;
&lt;p&gt;If you type that into your terminal (you don't copy and paste random multi-line commands from the internet directly into your terminal, right?) you'll see a simplified version of another one of Slack's example templates. In this case, it's a simple meeting reminder message with a bit of information and a nice little graphic to let you know that it's a calendar event.&lt;/p&gt;

&lt;p&gt;As for how these blocks actually work, let's go over what some of these bits are.&lt;/p&gt;

&lt;p&gt;The entire JSON object in the data option is a message payload. Before blocks you would have to include something like a &lt;code&gt;text&lt;/code&gt; key like in the first message example. Now with Blocks you can have just a &lt;code&gt;blocks&lt;/code&gt; key which will be an array of the blocks you want to include in your message. Because it's an array, you can send as many blocks in one message as you would like. This is what allows for extremely rich blocks like in the image I had at the start of this post.&lt;/p&gt;

&lt;p&gt;Within each block object you're required to have at the very least a &lt;code&gt;type&lt;/code&gt; property. The most general type you can have is a &lt;code&gt;section&lt;/code&gt;, which just means it's a generic type of block. You can also have &lt;code&gt;image&lt;/code&gt;, &lt;code&gt;context&lt;/code&gt;, &lt;code&gt;actions&lt;/code&gt;, and &lt;code&gt;divider&lt;/code&gt; type blocks, all of which have slightly different use cases.&lt;/p&gt;

&lt;p&gt;In the case of our example block, we included some text in the &lt;code&gt;text&lt;/code&gt; property. Text values are themselves an object, and can be either &lt;code&gt;mrkdwn&lt;/code&gt; or &lt;code&gt;plain_text&lt;/code&gt;. In this case we're using Markdown because the title of the meeting is a bold link. The text's &lt;code&gt;text&lt;/code&gt; property is where the actual text goes.&lt;/p&gt;

&lt;p&gt;Then finally, this section has a special extra bit called an accessory. An accessory can be an image, button, date picker, or a whole menu. In this case we added an image, specifically the image of a calendar icon.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3brc25q6yehs3dztdsve.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%2F3brc25q6yehs3dztdsve.png" alt="A Slack message styled to look like a calendar event reminder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a more in-depth dive on these rich message layouts, check out the official Slack documentation on &lt;a href="https://api.slack.com/messaging/composing/layouts" rel="noopener noreferrer"&gt;creating rich message layouts&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Block Kit is pretty new, and I haven't seen as much support for it as I'd like to. Since my current framework of choice is Laravel, I tried finding out if there was an easy way to send Block messages. While there is an official package to send notifications to Slack, they've decided to not support Block Kit 😞&lt;/p&gt;

&lt;p&gt;I've gone ahead and created a package that basically extends the official one, but with support for Block Kit included. If you use Laravel and are interested in taking advantage of this rich notification system, check out my package on GitHub!&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/nathanheffley" rel="noopener noreferrer"&gt;
        nathanheffley
      &lt;/a&gt; / &lt;a href="https://github.com/nathanheffley/laravel-slack-blocks" rel="noopener noreferrer"&gt;
        laravel-slack-blocks
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      An extension of the official `laravel/slack-notification-channel` package to add support for Slack Blocks.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Laravel Slack Blocks&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;This package is an extension of the official &lt;code&gt;laravel/slack-notification-channel&lt;/code&gt; package.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;
Thes core notifications package has finally built-in support for these rich Slack messages, and as such you should use the official package if you are able.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://laravel.com/docs/10.x/notifications#formatting-slack-notifications" rel="nofollow noopener noreferrer"&gt;https://laravel.com/docs/10.x/notifications#formatting-slack-notifications&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Usage&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;Instead of requiring the official package, you should require this one instead.&lt;/p&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;composer require nathanheffley/laravel-slack-blocks
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Because this package is built on top of the official one, you'll have all the functionality found in the &lt;a href="https://laravel.com/docs/5.8/notifications#slack-notifications" rel="nofollow noopener noreferrer"&gt;official docs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can follow those instructions with the slight adjustment of requiring the classes from &lt;code&gt;NathanHeffley\LaravelSlackBlocks&lt;/code&gt; instead of &lt;code&gt;Illuminate\Notifications&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Everything supported in the base Illuminate Notifications classes is supported in these extended classes.&lt;/p&gt;
&lt;p&gt;If you want to add a block to your Slack message, you need to add the block in an attachment.&lt;/p&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;use NathanHeffley\LaravelSlackBlocks\Messages\SlackMessage
// ...

public function toSlack($notifiable)
{
    return (new SlackMessage)
        -&amp;gt;attachment(function ($attachment) {
            $attachment-&amp;gt;block(function ($block) {
                $block&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/nathanheffley/laravel-slack-blocks" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



</description>
      <category>slack</category>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Do you pay to run any side projects?</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Sat, 24 Nov 2018 21:30:39 +0000</pubDate>
      <link>https://dev.to/nathanheffley/do-you-pay-to-run-any-side-projects-512p</link>
      <guid>https://dev.to/nathanheffley/do-you-pay-to-run-any-side-projects-512p</guid>
      <description>&lt;p&gt;I often hear stories about people dropping their side projects as soon as it costs them money to run. I've done it myself many, many times. Sometimes the project just isn't interesting enough or you're not excited enough to justify the cost.&lt;/p&gt;

&lt;p&gt;But I want to learn about some side projects that the dev community runs out of love, even though it costs them time (and maybe even some money) to keep it going for little to no return.&lt;/p&gt;

&lt;p&gt;So, if you have a side project that you don't monetize but keep working on and make sure it's running, what is it?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>sideprojects</category>
    </item>
    <item>
      <title>How I Host My Buzzword-Powered Blog For Free</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Thu, 22 Nov 2018 17:25:38 +0000</pubDate>
      <link>https://dev.to/nathanheffley/how-i-host-my-buzzword-powered-blog-for-free-2c77</link>
      <guid>https://dev.to/nathanheffley/how-i-host-my-buzzword-powered-blog-for-free-2c77</guid>
      <description>&lt;p&gt;My &lt;a href="https://www.nathanheffley.com/" rel="noopener noreferrer"&gt;blog&lt;/a&gt; is what I like to call "buzzword-powered" since it's my testing ground for new technology I want to try out. In its current form, it's a single-page &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; app, generated by &lt;a href="https://www.gatsbyjs.org/" rel="noopener noreferrer"&gt;Gatsby&lt;/a&gt;. The entire site is pre-rendered static pages so even if a user doesn't have JavaScript enabled they'll get the regular experience of loading each page over HTTP requests. But if a user does have JavaScript enabled, the site will turn into a single-page progressive web app which will continue to work even if they have a spotty internet connection, or lose access all together.&lt;/p&gt;

&lt;p&gt;In short, it's a mobile first, offline capable, pre-rendered static single-page progressive web app using React, generated by Gatsby.&lt;/p&gt;

&lt;p&gt;All of these buzzwords make for a fantastic user-experience, I hope. On the first visit, the site loads in about one second and only downloads about 500KB of data (that's only half a megabyte, while the average site these days are several megabytes). Now that the app is loaded, subsequent page loads are, for all intents and purposes, instant. Only a few bytes of data need to be transferred to ensure the page is up to date. Even if the user leaves the site and comes back in the future, the entire site loads even faster. Less than a second to render the site and only a few hundred bytes per page viewed to make sure everything is up to date.&lt;/p&gt;

&lt;p&gt;Not only is using my site easy for my readers, but it's easy for me as well. Running a static site is significantly easier and far more secure than other traditional blogging platforms like Wordpress. The biggest road-block to using a static site is that having a CMS is objectively more user-friendly than committing new files to a git repository or uploading new files to a server. That's why I decided to just use a CMS to handle the content for my blog. If you check out the code for my site (&lt;a href="https://github.com/NathanHeffley/blog" rel="noopener noreferrer"&gt;over on GitHub&lt;/a&gt;) you'll notice that none of my posts are there. That's because when building the site's static pages, it can pull data from &lt;a href="https://www.contentful.com/" rel="noopener noreferrer"&gt;Contentful&lt;/a&gt; and uses that information to generate the pages. This has allowed me to open-source my blog's framework without giving up my copyright on all the content I write for it.&lt;/p&gt;

&lt;p&gt;That brings me to the first part of how I host my content for free...&lt;/p&gt;

&lt;h2&gt;
  
  
  Free Content Management
&lt;/h2&gt;

&lt;p&gt;Contentful allows you to create different content types with various fields. This works out perfectly for something like a blog. Any time I want to write a new blog post, I just log in to Contentful, create a new post and fill in all the fields, and as soon as I publish the post it starts to go live. Because Gatsby only pulls data from the API when it builds the site, and because it only builds the site when something has changed (either the code or the content) I never have to worry about hitting any sort of rate limits. I'm the only one who writes for my blog, and I certainly don't have dozens of content types or thousands of posts, which allows me to easily stay within the restrictions of their free plan.&lt;/p&gt;

&lt;p&gt;Normally, editing content on an external service like Contentful wouldn't cause a site hosted on a different server to update. But because of the power of webhooks, any time I save an update on Contentful it sends a message to my hosting platform to rebuild the site.&lt;/p&gt;

&lt;p&gt;Which brings me to the final part of how I actually &lt;em&gt;host&lt;/em&gt; my whole site for free...&lt;/p&gt;

&lt;h2&gt;
  
  
  Free Static Site Hosting
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.netlify.com/" rel="noopener noreferrer"&gt;Netlify&lt;/a&gt; is a fantastic service if you're looking to host static sites. The biggest restriction is that the free plan only allows for one account, but that's fine if you're a lone-wolf developer (or the kind of person who shares Netflix accounts). If that restriction isn't a problem for you, and none of the extra features are must-haves, then you won't hit any resistance to using Netlify. A site can be pulled directly from your git repository and their server will run whatever build commands you need to run in order to build the site. After the site is built they'll deploy the static files to their CDN.&lt;/p&gt;

&lt;p&gt;Any time you make a new commit to your git repository's master branch (or whatever branch you deploy from), Netlify will rebuild your site automatically and deploy it.&lt;/p&gt;

&lt;p&gt;More importantly is updating when new content is published in Contentful. As I mentioned, any time I save new content a webhook will be called. More specifically, a Netlify webhook is called with a secret key which triggers a site rebuild. Gatsby grabs the new content and builds a page for it, and updates whatever else needs to be updated when a page is added.&lt;/p&gt;

&lt;h2&gt;
  
  
  All Together
&lt;/h2&gt;

&lt;p&gt;So that's how &lt;a href="https://www.nathanheffley.com/" rel="noopener noreferrer"&gt;my buzzword-powered blog&lt;/a&gt; is hosted. I hope this has encouraged you to come up with creative ways you can provide your users with a blazing fast experience that doesn't sacrifice cool features and buzzwords, all without giving up your CMS or paying anything to host it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: This post was not sponsored. I encourage you to use these services (for free) if you are interested because they are fantastic services that I enjoy using.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>gatsby</category>
      <category>free</category>
      <category>hosting</category>
    </item>
    <item>
      <title>Laravel + React: Posting Threads</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Fri, 12 Jan 2018 23:39:15 +0000</pubDate>
      <link>https://dev.to/nathanheffley/laravel--react-posting-threads-bc3</link>
      <guid>https://dev.to/nathanheffley/laravel--react-posting-threads-bc3</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://www.nathanheffley.com/blog/laravel-react-posting-threads"&gt;nathanheffley.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is the first lesson in a series on how to create a forum using Laravel and React. If you haven't read the introduction where we &lt;a href="https://www.nathanheffley.com/blog/laravel-react-planning-a-forum"&gt;plan out the forum&lt;/a&gt; you should check it out first!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To get started with a forum, the first thing we need is the ability to create accounts, login, and create threads. Thankfully, Laravel comes with the Artisan &lt;code&gt;make:auth&lt;/code&gt; command, which we'll be taking advantage of. Since this is covered pretty thoroughly other places, like in the &lt;a href="https://laravel.com/docs/5.5/authentication"&gt;Laravel Authentication documentation&lt;/a&gt;, I won't go over it again. Just know that I simply ran the &lt;code&gt;php artisan make:auth&lt;/code&gt; command and didn't change any of the related files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating New Threads
&lt;/h2&gt;

&lt;p&gt;The first goal in making a forum will be allowing users to publish threads. With the default authentication system we get a &lt;code&gt;/home&lt;/code&gt; route and page. We'll make use of this to show a user important information, like threads they've created and notifications they've received. For right now though, we'll add a sidebar with a form to create a new page. The template is pretty simple, so replace what's in the auto-generated template with our new home page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@extends('layouts.app')

@section('content')
&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;"container"&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;class=&lt;/span&gt;&lt;span class="s"&gt;"row"&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;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-5 col-md-offset-7"&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;id=&lt;/span&gt;&lt;span class="s"&gt;"create-thread"&lt;/span&gt;&lt;span class="nt"&gt;&amp;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;/div&amp;gt;&lt;/span&gt;
@endsection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That div with an id of &lt;code&gt;create-thread&lt;/code&gt; is where our React form will be going. Using React for something simple like a form may seem like a little bit of overkill, but it will allow us to add extra functionality as we move forward and starting out we can make use it to submit an Ajax request instead of forcing the user to load a whole new page. As we add more components to this page, you'll see just how useful using React for all of these interactive pieces can be.&lt;/p&gt;

&lt;p&gt;Before we move on to creating the actual React code, lets quickly go over the back-end code that will be powering the creation of new threads.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Back-End Functionality
&lt;/h2&gt;

&lt;p&gt;To actually create threads, we'll need a database migration. For right now, we need nothing more than an &lt;code&gt;author_id&lt;/code&gt; column to reference who created the thread, as well as a title and content column. In the future we'll be adding more columns, but this is good enough to get us started. You can check out &lt;a href="https://github.com/NathanHeffley/react-forum/blob/251939322e9d0ad9558721907f8809ac11bd442e/database/migrations/2018_01_11_193047_create_threads_table.php"&gt;the full migration on GitHub&lt;/a&gt;. If you're following along, make sure to create that migration (I recommend just running &lt;code&gt;php artisan make:migration create_threads_table --create=threads&lt;/code&gt; and editing it to match my file) and refresh your database.&lt;/p&gt;

&lt;p&gt;Since threads will be an actual model that we'll be interacting with, we'll need a model as well. Starting out simple, the only thing I've put into the model is a &lt;code&gt;$fillable&lt;/code&gt; property so that we avoid mass-assignment exceptions and an Eloquent relationship for accessing the threads author (and of course I added the matching relationship in the User class as well, you can &lt;a href="https://github.com/NathanHeffley/react-forum/commit/1bde7f36b7d0bc809c6ee85279766dbbf53d99cb#diff-36f1184e0453df972dab51127e08458f"&gt;view that diff here&lt;/a&gt;). &lt;a href="https://github.com/NathanHeffley/react-forum/blob/251939322e9d0ad9558721907f8809ac11bd442e/app/Thread.php"&gt;Here is the Thread class&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And finally, none of this would be very useful if we didn't also have a controller to handle incoming requests. You can create a blank controller with &lt;code&gt;php artisan make:controller ThreadsController&lt;/code&gt; and then add these few functions.&lt;/p&gt;

&lt;p&gt;This one is pretty straightforward and will simply show a single thread.&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;?php

public function show(Thread $thread)
{
    return view('threads.show', compact('thread'));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where we'll actually be storing new threads. First we validate that the title and content data values are present. Then we actually create the thread with the values and also set the &lt;code&gt;author_id&lt;/code&gt; to be the id of the currently authenticated user.&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;?php

public function store(Request $request)
{
    $request-&amp;gt;validate([
        'title' =&amp;gt; 'required',
        'content' =&amp;gt; 'required',
    ]);

    $thread = Thread::create([
        'author_id' =&amp;gt; \Auth::user()-&amp;gt;id,
        'title' =&amp;gt; $request-&amp;gt;title,
        'content' =&amp;gt; $request-&amp;gt;content
    ]);

    return response($thread, 201);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that you've seen the two useful functions, go back up to the top of the controller and add a constructor. This is simply to ensure only authenticated users can make a POST request to create a thread. Since we'll be adding more functions in the future, I decided it was best to just require authentication on everything except simply viewing a thread.&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;?php

public function __construct()
{
    $this-&amp;gt;middleware('auth')-&amp;gt;except('show');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we just need some routes for creating and viewing threads and calling these controller functions. Throw these two routes into your &lt;code&gt;route/web.php&lt;/code&gt; file to handle that.&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;?php

Route::get('/threads/{thread}', 'ThreadsController@show');
Route::post('/threads', 'ThreadsController@store');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating Threads With React
&lt;/h2&gt;

&lt;p&gt;Now that the back-end is all setup and ready to go, lets create that form component!&lt;/p&gt;

&lt;p&gt;First, go into your &lt;code&gt;resources/assets/js&lt;/code&gt; folder and open up &lt;code&gt;app.js&lt;/code&gt;. In there you'll see a line that pulls in the Example component. Go ahead and change that so it pulls in a more descriptive 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="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/CreateThread&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go into that components folder and rename the Example.js file to be CreateThread.js. This will be our form component.&lt;/p&gt;

&lt;p&gt;By default, you should see that the file imports React and ReactDOM. Since we're going to making Ajax requests from this component, we'll also require Axios (which comes configured by default in every Laravel project).&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&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;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&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;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we'll update what comes in the file by default and then add in our own functions to get the functionality we need. Make sure to update the class name definition from Example to CreateThread and do the same for the ReactDOM.render at the end. We need to check if the page has the &lt;code&gt;create-thread&lt;/code&gt; id element that we will use anywhere we want this component to load. Since a page will only ever have one of these forms, this simple check will work just fine and is the perfect starting place for our first&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CreateThread&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Omitted for brevity right now.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create-thread&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="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CreateThread&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create-thread&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the basic setup stuff is taken care of, we can work on rewriting the render method. We'll have the component always output itself as a self-contained panel. The majority of this code is just Bootstrap divs and styling. The important things to pay attention to are the &lt;code&gt;onChange&lt;/code&gt; attributes on the input and textarea elements, and the &lt;code&gt;onClick&lt;/code&gt; attribute on the button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"panel panel-default"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"panel-heading"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Create a New Thread&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"panel-body"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="na"&gt;htmlFor&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"new-thread-title"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Title&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;label&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"new-thread-title"&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;changeTitle&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="na"&gt;htmlFor&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"new-thread-content"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Title&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;label&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;textarea&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"new-thread-content"&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;changeContent&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"8"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;textarea&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"panel-footer"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;postThread&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    Publish
                &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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 that we have the render function all taken care of, we need to create those &lt;code&gt;changeTitle()&lt;/code&gt;, &lt;code&gt;changeContent()&lt;/code&gt;, and &lt;code&gt;postThread()&lt;/code&gt; functions.&lt;/p&gt;

&lt;p&gt;The title and content functions are easiest, since they'll just be updating the components state. The &lt;code&gt;event&lt;/code&gt; parameter is automatically passed to the function by React because of how the &lt;code&gt;onChange&lt;/code&gt; event attribute is handled. With the &lt;code&gt;event&lt;/code&gt; object we simply select the &lt;code&gt;target&lt;/code&gt; which will be either the input or textarea element and then select the value from that.&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;changeTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;setState&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="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;changeContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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;The &lt;code&gt;postThread()&lt;/code&gt; function is a bit more involved, but we'll start out with the most basic Axios call we can get away with for right now. We'll come back to this function in the future when we add some new features and options for posting threads.&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;postThread&lt;/span&gt;&lt;span class="p"&gt;()&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="nx"&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;/threads&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="na"&gt;title&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;content&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&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;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;setState&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="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new-thread-title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new-thread-content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you've ever worked with Axios before then this function will be pretty straight-forward. Even if you haven't used it before, I'm sure you're all smart enough to figure it out. We're simply using Axios to make a POST request to the &lt;code&gt;/threads&lt;/code&gt; path on our site which we set up earlier to accept POST requests and send them to the ThreadsController. In that POST request we're passing the title and content data which is stored in the components state (put there by the &lt;code&gt;changeTitle&lt;/code&gt; and &lt;code&gt;changeContent&lt;/code&gt; functions). Axios works using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;Promises&lt;/a&gt; so that after a request has been completed and a response is received, the &lt;code&gt;then&lt;/code&gt; function gets called. Inside of that we reset the components state to have empty values and clear out the title and content inputs.&lt;/p&gt;

&lt;p&gt;The final bit of this controller that we need is a constructor. We need to setup the initial state of the component, and also bind &lt;code&gt;this&lt;/code&gt; to each of the functions we created. I go over why we need to doing this binding in my post on &lt;a href="https://www.nathanheffley.com/blog/getting-started-with-react-in-laravel-5-5"&gt;getting started with React&lt;/a&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="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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;state&lt;/span&gt; &lt;span class="o"&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="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postThread&lt;/span&gt; &lt;span class="o"&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;postThread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;changeTitle&lt;/span&gt; &lt;span class="o"&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;changeTitle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;changeContent&lt;/span&gt; &lt;span class="o"&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;changeContent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to see the whole file, &lt;a href="https://github.com/NathanHeffley/react-forum/blob/251939322e9d0ad9558721907f8809ac11bd442e/resources/assets/js/components/CreateThread.js"&gt;view it on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That's it! We now have a component that can create threads on our forum using React and Axios. Visit your project (or &lt;a href=""&gt;clone it from GitHub&lt;/a&gt;) and go to the &lt;code&gt;/home&lt;/code&gt; path to see the form. If you try submitting it you might not see much happen, but if you check out your browser's developer tools you should be able to see a POST request going to &lt;code&gt;/threads&lt;/code&gt;. After submitting a thread, try visiting &lt;code&gt;/threads/1&lt;/code&gt; and you should be able to see the first thread you created.&lt;/p&gt;

&lt;p&gt;This lack of feedback isn't very user friendly, so in the next lesson we'll work on creating some sort of alert component to tell users that their thread was successfully created and give them a link to view it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>laravel</category>
      <category>javascript</category>
      <category>php</category>
    </item>
    <item>
      <title>Laravel + React: Planning a Forum</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Fri, 05 Jan 2018 16:07:34 +0000</pubDate>
      <link>https://dev.to/nathanheffley/laravel-55-react-tutorial-planning-a-forum-h1o</link>
      <guid>https://dev.to/nathanheffley/laravel-55-react-tutorial-planning-a-forum-h1o</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://www.nathanheffley.com/blog/laravel-react-planning-a-forum"&gt;nathanheffley.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After getting React set up in your Laravel project (check out how to &lt;a href="https://www.nathanheffley.com/blog/getting-started-with-react-in-laravel-5-5"&gt;get started with React in Laravel 5.5&lt;/a&gt; if you haven't used the new preset before), you may be wondering how to actually use it on your site.&lt;/p&gt;

&lt;p&gt;In this series, we'll create a simple forum which uses React components for the main features of the site. Starting out, we'll focus on the main features (creating threads, commenting, etc). Later on we'll explore more advanced features such as voting, popular/hot algorithms, messaging, and following other users.&lt;/p&gt;

&lt;p&gt;Let's look at the core components that we'll be creating over the next couple of lessons.&lt;/p&gt;

&lt;h2&gt;
  
  
  List of Threads
&lt;/h2&gt;

&lt;p&gt;This will be the first thing that users will see when visiting the site. There's no point in going to a forum if you can't see a list of all the threads, right? We'll start out by creating a component that will take data about threads and display them in a chronological order (once we implement voting we can change this to show high-quality threads towards the top). Pagination will also be included in this component, and how to use Laravel's built-in pagination feature to create a React-powered element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thread
&lt;/h2&gt;

&lt;p&gt;In order to allow a user to edit or delete their thread, we'll create a component that displays a thread to everyone but only shows the controls to the author. To keep a nice flow on the front-end, we'll also make use of Ajax calls to the back-end which will validate everything of course.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;The comments will be similar to the thread list component, in that we'll paginate and display a list of all the comments for a particular thread. We'll also give the author some controls like on a main thread component.&lt;/p&gt;

&lt;h2&gt;
  
  
  GitHub
&lt;/h2&gt;

&lt;p&gt;Throughout this series, I'll have a GitHub repo open tracking all the changes. I'll make sure to reference the most recent commit at the start and end of each lesson, so that you can catch up if you fall behind or just skip ahead to the next lesson if you don't want to write the code yourself.&lt;/p&gt;

&lt;p&gt;I've already set it up with a basic Laravel project with the React preset already configured (again, check out my previous post to learn more about that). Go on over to my &lt;a href="https://github.com/NathanHeffley/react-forum"&gt;react-forum repository&lt;/a&gt; to check that out. Along the way I would love to see issues and pull requests for things I mess up or just for new features/lessons that you would like to see covered in this series!&lt;/p&gt;

&lt;p&gt;Next week we'll get started with quickly setting up the authentication system and then allowing users to post new threads, which will give us the opportunity to start creating the Thread List component.&lt;/p&gt;

</description>
      <category>react</category>
      <category>laravel</category>
      <category>javascript</category>
      <category>php</category>
    </item>
    <item>
      <title>Learning Laravel: Eyeing Up Views</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Fri, 29 Dec 2017 21:37:45 +0000</pubDate>
      <link>https://dev.to/nathanheffley/learning-laravel-eyeing-up-views-1enb</link>
      <guid>https://dev.to/nathanheffley/learning-laravel-eyeing-up-views-1enb</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://www.nathanheffley.com/blog/learning-laravel-eyeing-up-views"&gt;nathanheffley.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that we've started learned how to set up some basic routes (go check out &lt;a href="https://dev.to/blog/learning-laravel-really-radical-routing"&gt;Really Radical Routing&lt;/a&gt; if you haven't created any routes yet), lets give our site visitors something to look at that's a bit nicer than some plain text&lt;/p&gt;

&lt;p&gt;Views will allow you to use a templating engine called Blade to create HTML pages with ease. You can check out the default page that gets created when you first make a Laravel project inside &lt;code&gt;resources/views/welcome.blade.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Within that file, you'll see a basic HTML page with some Blade-specific content. Here's the file with some of the extraneous content taken out:&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 lang="{{ app()-&amp;gt;getLocale() }}"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;!-- HEAD CONTENT --&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="flex-center position-ref full-height"&amp;gt;
      @if (Route::has('login'))
        &amp;lt;div class="top-right links"&amp;gt;
          @auth
            &amp;lt;a href="{{ url('/home') }}"&amp;gt;Home&amp;lt;/a&amp;gt;
          @else
            &amp;lt;a href="{{ route('login') }}"&amp;gt;Login&amp;lt;/a&amp;gt;
            &amp;lt;a href="{{ route('register') }}"&amp;gt;Register&amp;lt;/a&amp;gt;
          @endauth
        &amp;lt;/div&amp;gt;
      @endif
      &amp;lt;div class="content"&amp;gt;
        &amp;lt;!-- PAGE CONTENT --&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first example of some blade templating is encountered within the first two lines. The most basic way to use Blade is to simply use it as a way to output the value of some PHP code to the page. The way that you let Blade know that you want to evaluate a snippet of PHP code and put the result directly into the HTML code is to use double curly braces.&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;html lang="{{ app()-&amp;gt;getLocale() }}"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Blade will encounter this line, evaluate the code within the curly braces (in this example it's a call to a function) and then output the result of that function into the &lt;code&gt;lang&lt;/code&gt; attribute of the HTML tag. In this example, &lt;code&gt;app()-&amp;gt;getLocale()&lt;/code&gt; is a special Laravel function to get, of all things, the current locale.&lt;/p&gt;

&lt;p&gt;Further down in the file, we encounter something a little more interesting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@if (Route::has('login'))
  &amp;lt;!-- inner stuff --&amp;gt;
@endif
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're an astute reader, you may have already guessed that is an &lt;code&gt;if&lt;/code&gt; statement just like you would use in regular PHP code. This is simply checking to see if a &lt;code&gt;login&lt;/code&gt; route exists. Anything that is within one of these &lt;code&gt;@if/@endif&lt;/code&gt; sections will only be output/evaluated if the conditional is true. If you want to get technical, in Blade templating speak, this is called an "if directive". Any time you see an &lt;code&gt;@&lt;/code&gt; symbol with a keyword in a Blade file, you're looking at a directive.&lt;/p&gt;

&lt;p&gt;These directives are what make Blade really powerful. In a future post we may look into creating our own directives, but for right now we'll look at a special one that Laravel offers out of the box:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@auth
  &amp;lt;a href="{{ url('/home') }}"&amp;gt;Home&amp;lt;/a&amp;gt;
@else
  &amp;lt;a href="{{ route('login') }}"&amp;gt;Login&amp;lt;/a&amp;gt;
  &amp;lt;a href="{{ route('register') }}"&amp;gt;Register&amp;lt;/a&amp;gt;
@endauth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This directive checks to see if the current user is authenticated (logged in) to the site. Normally you would have to use an if statement to check if the user is authenticated, but this handy-dandy directive hides all that messy code behind and nice simple &lt;code&gt;@auth&lt;/code&gt; keyword. Because this is basically an &lt;code&gt;if&lt;/code&gt; statement in disguise, you can use &lt;code&gt;else&lt;/code&gt; just like you normally would. These directives are what gives Blade some of the magic that makes it much nicer for templating than straight PHP code.&lt;/p&gt;

&lt;p&gt;Now that you understand what curly braces and directives mean in templates, let's create our own view to use in place of that boring "Hello, World!" from the last article.&lt;/p&gt;

&lt;p&gt;Create a new file in the &lt;code&gt;resources/views&lt;/code&gt; directory called &lt;code&gt;layout.blade.php&lt;/code&gt; and inside of it we'll setup the outline of any HTML document.&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;title&amp;gt;Learning Laravel&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    @yield('content')
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;@yield&lt;/code&gt; directive is one of the more important directives that you'll be using when creating Blade templates. It allows you to &lt;em&gt;extend&lt;/em&gt; this template file and place more code right where the &lt;code&gt;@yield&lt;/code&gt; is. The parameter that &lt;code&gt;yield&lt;/code&gt; takes allows you to create multiple sections and place them in different places. You can have as many &lt;code&gt;yield&lt;/code&gt; directives as you want as long as they have different names. Pretty nifty! Now let's create the actual view for our route. Make one more file in &lt;code&gt;resources/views&lt;/code&gt; and name it &lt;code&gt;hello.blade.php&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@extends('layout')

@section('content')
  &amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;
@endsection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we use the &lt;code&gt;@extends&lt;/code&gt; directive to tell Blade which file we want to &lt;em&gt;extend&lt;/em&gt; and because Blade is so clever, it knows that all template files will end in &lt;code&gt;.blade.php&lt;/code&gt; so we can leave that bit off and just give it the first part of the filename. Then we use the &lt;code&gt;@section&lt;/code&gt; directive and pass it the same value that we gave to the &lt;code&gt;@yield&lt;/code&gt; directive in the layout file. This is how Blade knows where this section belongs in the layout template.&lt;/p&gt;

&lt;p&gt;Now that we have our very own view created, let's go back to the &lt;code&gt;routes/web.php&lt;/code&gt; file and open it up again. Go to where we defined our &lt;code&gt;/hello&lt;/code&gt; route in the previous lesson and change it so that we return a view instead.&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;?php

Route::get('/hello', function () {
    return view('hello');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like Blade, Laravel knows that our file will end in &lt;code&gt;.blade.php&lt;/code&gt; so we can leave that off. Now if you save that and check out your site's route (most likely at &lt;a href="http://localhost:8000/hello"&gt;localhost:8000/hello&lt;/a&gt;) you should see an actual HTML page with an &lt;code&gt;h1&lt;/code&gt; instead of just plain text.&lt;/p&gt;

&lt;p&gt;You now how everything you need to create a site with Laravel! You can create routes, display actual HTML pages, and even do a little bit of programming logic if you want. But putting code in the route file isn't a great way to keep things organized, and just returning basic pages isn't very interesting. In the next lesson we'll look at a brief overview of the project we'll build together to learn how you can use Laravel to build real-world projects. Make sure to check back so you don't miss it!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>views</category>
      <category>learning</category>
      <category>php</category>
    </item>
    <item>
      <title>Learning Laravel: Really Radical Routing</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Wed, 20 Dec 2017 16:25:51 +0000</pubDate>
      <link>https://dev.to/nathanheffley/learning-laravel-really-radical-routing-4e9h</link>
      <guid>https://dev.to/nathanheffley/learning-laravel-really-radical-routing-4e9h</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://www.nathanheffley.com/blog/learning-laravel-really-radical-routing"&gt;nathanheffley.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since a route is the first thing every user is going to interact with when visiting your site, it's where we're going to start our Laravel journey.&lt;/p&gt;

&lt;p&gt;In most projects, your routes will be contained within the &lt;code&gt;routes\web.php&lt;/code&gt; file. When you open it up after creating a brand new project (read the first lesson in this series if you need help &lt;a href="https://www.nathanheffley.com/blog/learning-laravel-installation-configuration"&gt;setting up a Laravel project&lt;/a&gt;) you will see the generic starting route:&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;?php

Route::get('/', function () {
    return view('welcome');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break this down to figure out what's going on.&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;?php

Route::get('/', function () {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we call the &lt;code&gt;get&lt;/code&gt; function on the Route facade. As you may have guessed, this is setting up a route that will respond to GET requests. The first parameter in this function is the actual route itself. In this case the route is set up for the root url. Assuming that our site is being run locally, this route is going to handle any GET requests that are made to &lt;code&gt;localhost:8000&lt;/code&gt;. Any other type of request such as POST or any request to a different path like &lt;code&gt;localhost:8000/example&lt;/code&gt; will ignore this route and keep looking for a better match.&lt;/p&gt;

&lt;p&gt;The second parameter, the function, is what gets called whenever somebody makes a request to the server that matches this route. In upcoming lessons I'll show you how to extract this function to other files, but for right now we'll stick with this. For small projects or simple routes, using a function directly in your routes file is a viable option.&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;?php

return view('welcome');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the function we are simply returning this thing called a view. The &lt;code&gt;view&lt;/code&gt; function is a special Laravel helper that takes a string that is then translated into the name of a file which is returned. Views will be covered in the next lesson, so make sure to check back in to learn exactly what this is doing. For right now, just rest assured that this is returning a view called 'welcome'. When you create a new project and visit it for the first time at &lt;code&gt;localhost:8000&lt;/code&gt;, this view is what displays the large "Laravel" text and several links you see.&lt;/p&gt;

&lt;p&gt;All in all, this route is saying that whenever somebody GETs the '/' route they should be sent back the 'welcome' view.&lt;/p&gt;

&lt;p&gt;Lets create our own route. We won't worry about other files or views and just return a simple string.&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;?php

Route::get('/hello', function () {
    return 'Hello, World!';
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now visit &lt;code&gt;localhost:8000/hello&lt;/code&gt; and you should see "Hello, World!" output in plain old text on your screen. Congratulations, you've created a fully-functioning route in Laravel!&lt;/p&gt;

&lt;p&gt;Of course most routes you create from here on out won't be quite this simple. In the next lesson we'll go over creating views so that you can return fully valid HTML pages. After that lesson you'll be able to use Laravel to create an entire website, albeit with limited functionality.&lt;/p&gt;

&lt;p&gt;Although this may have seemed like an overly simple lesson, that's only because Laravel makes it so easy. We'll definitely be revisiting routes in the future as there is a lot more power hidden here, but we need to cover some more of the basics before we can use those features to their full potential!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>routes</category>
      <category>learning</category>
      <category>php</category>
    </item>
    <item>
      <title>Learning Laravel: Installation and Configuration</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Sat, 11 Nov 2017 16:26:11 +0000</pubDate>
      <link>https://dev.to/nathanheffley/learning-laravel-installation-and-configuration-144</link>
      <guid>https://dev.to/nathanheffley/learning-laravel-installation-and-configuration-144</guid>
      <description>&lt;p&gt;Laravel is the "PHP Framework For Web Artisans" and it's become a hot topic in PHP back-end development over the past few years. Before you can start learning it though, you need to learn how to set up a new project using it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: this article will assume you already have PHP 7, Composer, NPM, and MySQL installed on your development computer. While this is a beginner lesson for Laravel, it isn't a lesson for these other foundational systems. PHP is notoriously difficult to set up on Windows, so for the sake of brevity, I will not be covering that in this article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installing Laravel
&lt;/h2&gt;

&lt;p&gt;To get started with Laravel, you'll first need to install the command line tool. This tool will allow you to quickly spin up new projects. All you need to do is use Composer to require the dedicated installer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer global require "laravel/installer"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To be able to use this new command anywhere throughout your system, you'll need to make sure your Composer vendor bin as part of your $PATH system variable. Once you have the installer successfully configured, you can test it out by trying to create a new project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;laravel new sitename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If all goes well, you will have a new folder called sitename that now contains a brand new Laravel project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading The Dependencies
&lt;/h2&gt;

&lt;p&gt;Now that you have your project scaffolding created, &lt;code&gt;cd&lt;/code&gt; into your sitename folder and get ready to work. The first thing you'll need to do is install the dependencies. With Composer, this is as easy as possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait a little bit depending on your computer and internet connection, and you'll be good to go!&lt;/p&gt;

&lt;p&gt;Laravel also comes with a build system built-in that uses Webpack to compile your JavaScript and Sass, as well as serving Vue to the front-end. To take advantage of this pre-configured system, you'll need to install your NPM dependencies as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install

npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anytime you want to compile your assets all you have to do is run the &lt;code&gt;dev&lt;/code&gt; command and everything will be compiled down to your public directory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once you go to launch your site on a production server, there is also an &lt;code&gt;npm run prod&lt;/code&gt; command that you should use instead of &lt;code&gt;dev&lt;/code&gt;. While developing, there is also a handy &lt;code&gt;npm run watch&lt;/code&gt; command which will recompile your assets any time you make a change to any of them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With all of your dependencies installed, you can move onto the final step of setting up your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Your New Project
&lt;/h2&gt;

&lt;p&gt;All that's left is to change the actual configuration files. Within your project, there should be a file named &lt;code&gt;.env&lt;/code&gt;. If you can't find it, copy the &lt;code&gt;.env.example&lt;/code&gt; file and create a &lt;code&gt;.env&lt;/code&gt; file yourself. Within this file are where you most important configuration settings belong. If you use source control like Git (and you should) do not commit this file to your repository. It will contain sensitive data, like your database username and password, and any other API tokens or passwords you need while developing your application.&lt;/p&gt;

&lt;p&gt;For just getting Laravel up and running we don't actually need to change any settings in here for right now. The first settings you will most likely change though when working on your own projects are the &lt;code&gt;DB_DATABASE&lt;/code&gt;, &lt;code&gt;DB_USERNAME&lt;/code&gt;, and &lt;code&gt;DB_PASSWORD&lt;/code&gt; variables. I'll let you figure out what you should put in each of those when the time comes!&lt;/p&gt;

&lt;p&gt;Before you can actually view the site though, you do need to set a value for the &lt;code&gt;APP_KEY&lt;/code&gt; variable. You could just type a bunch of random letters and numbers there manually, or you can go back to your terminal and use a built-in command that comes with Laravel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan key:generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a message that your &lt;code&gt;Application key [base64:gibberishhere=] set successfully.&lt;/code&gt; If you were to look at your &lt;code&gt;.env&lt;/code&gt; file again you would see that &lt;code&gt;APP_KEY&lt;/code&gt; is now set, and you are all set to finally check out your project in the browser!&lt;/p&gt;

&lt;p&gt;If you have a local server system set up like Apache or Nginx, you could create a server that points users to your &lt;code&gt;/sitename/public&lt;/code&gt; directory. For development purposes though, you can simply use another one of the built-in artisan commands to spin-up a local server.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;There will be a message saying that a &lt;code&gt;Laravel development server started&lt;/code&gt; and a URL. You should be able to visit either &lt;code&gt;http://localhost:8000&lt;/code&gt; or &lt;code&gt;http://127.0.0.1:8000&lt;/code&gt; and see the default welcome page that comes pre-installed!&lt;/p&gt;

&lt;p&gt;Congratulations! You're now ready to start creating amazing websites. I can't wait to see what incredible creations you come up with, I'd love to hear about them.&lt;/p&gt;




&lt;p&gt;If you're interested in learning more about Laravel or just want to chat, &lt;a href="https://www.nathanheffley.com"&gt;check out my website.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear what you guys think. Anybody interested in more beginner Laravel tutorials?&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>learning</category>
      <category>framework</category>
      <category>php</category>
    </item>
    <item>
      <title>Getting Started With React in Laravel 5.5</title>
      <dc:creator>Nathan Heffley</dc:creator>
      <pubDate>Thu, 02 Nov 2017 20:48:26 +0000</pubDate>
      <link>https://dev.to/nathanheffley/getting-started-with-react-in-laravel-55-363</link>
      <guid>https://dev.to/nathanheffley/getting-started-with-react-in-laravel-55-363</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://www.nathanheffley.com/blog/getting-started-with-react-in-laravel-5-5"&gt;nathanheffley.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;By default, the newest versions of Laravel ship with scaffolding for the JavaScript framework &lt;a href="https://vuejs.org/"&gt;Vue.js&lt;/a&gt;. This is great for getting started quickly... if you plan on using it.&lt;/p&gt;

&lt;p&gt;Another popular choice for front-end JavaScript is Facebook's &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt;. Previously in Laravel, if you wanted to use React in your project you had to manually remove Vue and add React. While it wasn't terribly difficult, it did require pulling in the packages, adding it to your app.js or bootstrap.js files, fixing your webpack files, and so on.&lt;/p&gt;

&lt;p&gt;But now that Laravel 5.5 has shipped, there is a new artisan command available that handles all of this for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php artisan preset react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This short command replaces all the Vue scaffolding with React. If you would like to follow along with the rest of this lesson, open your terminal and go to wherever you place your Laravel projects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ laravel new laravel-react

$ cd laravel-react

$ php artisan preset react

$ npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you'd prefer to just look at the finished project, I have it &lt;a href="https://github.com/NathanHeffley/Laravel-React"&gt;hosted over on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that you have a fresh Laravel installation with React scaffolding in place, you're ready to go! Using React within another project such as this can be a little confusing, so we'll build a simple counter component to get started.&lt;/p&gt;

&lt;p&gt;When you first run the preset command, you will be given a default React component located at /resources/assets/js/components/Example.js. Rename this to Counter.js, and strip out all the example fluff and we're left with this much simpler component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&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;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Counter Component&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;counter&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="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;counter&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we did was rename the component and take out the extraneous code. Since we renamed the component file, we also have to go into our &lt;code&gt;/resources/assets/js/app.js&lt;/code&gt; file and update the name there as well So now instead of requiring the Example component, we require our Counter component.&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;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Counter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, to get the component displaying on the screen so we know everything is working as expected, we can edit the welcome.blade.php view to display our component. Simply remove the default &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; and replace it with this bit of HTML.&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&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;"container"&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;id=&lt;/span&gt;&lt;span class="s"&gt;"counter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/js/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&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;Because we used &lt;code&gt;ReactDOM.render(..., document.getElementById('counter'));&lt;/code&gt; in our component, it will find that &lt;code&gt;&amp;lt;div id="counter"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; and turn it into our new Counter component. The script is simply our main app.js script that everything gets compiled down into when you run the build script. Speaking of which, make sure to run that now that we've created our component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you visit your project in your browser, you should see an extremely exciting "Counter Component" paragraph on the page.&lt;/p&gt;

&lt;p&gt;Don't worry, it gets better. If you want to catch up with the GitHub project, you can jump to the &lt;a href="https://github.com/NathanHeffley/Laravel-React/commit/f8533747811232e36466f2fa9340b442b7ecd8e4"&gt;Install and Run Dev&lt;/a&gt; commit.&lt;/p&gt;

&lt;p&gt;Now that our component is displaying on the page, it means we can start adding some custom functionality. Since we said this was going to be a counter, let's follow through on that promise.&lt;/p&gt;

&lt;p&gt;The first thing we'll do is setup the state for the counter, which is where the current count will be stored. Go back into your Counter.js file and add this constructor just inside the component declaration.&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;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&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;Since we have the state declared, we may as well start displaying it on the page. Change the render function to output our exciting new count state instead of that boring old paragraph.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;classname&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Run your build script again to compile all of this down, and reload your page to see the current count get output to the screen! If you've fallen behind or simply want to see the code, we just completed the &lt;a href="https://github.com/NathanHeffley/Laravel-React/commit/6496fb2ee5f904488ac25074f2925af2d8ceb380"&gt;Setup State&lt;/a&gt; commit.&lt;br&gt;
It's still not very much like a counter though, since we can't actually interact with it to change the state. To make this as generic as possible so it can count whatever types of things you want, we'll simply add two buttons: one to increase the count and one to decrease it. Put these right below where we output the count.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"{this.increment}"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"{this.decrement}"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;-&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These buttons would work great, but right now we don't have an increment or a decrement function, so let's add those next. Put these two functions right between the constructor and the render function.&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;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&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;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;count&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;They're pretty straightforward. Running the increment function will increase the count state by one, running the decrement function will decrease the count state by one. Since we are using &lt;code&gt;this&lt;/code&gt; inside of a function on a component though, don't forget to bind &lt;code&gt;this&lt;/code&gt; to the function. To learn more about why you need to do this and other ways to do so, check out these &lt;a href="https://www.sitepoint.com/bind-javascripts-this-keyword-react/"&gt;6 Ways to Bind JavaScript's this keyword in React&lt;/a&gt;.&lt;br&gt;
Personally, I bind the functions at the end of my component's constructor like so.&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;constructor&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&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;increment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;decrement&lt;/span&gt; &lt;span class="o"&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;decrement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can successfully compile your code one more time and have a fully functioning React component inside Laravel! If you check out the site in your browser, you should see the default count of 0 and two little buttons. Clicking on either one should change the count and update the value being displayed just like you would expect.&lt;/p&gt;

&lt;p&gt;There you have it! Now you can quickly and easily get started using React in all of your Laravel projects (if you want) without having to fumble around in configuration files.&lt;/p&gt;

&lt;p&gt;You can check out the &lt;a href="https://github.com/NathanHeffley/Laravel-React/"&gt;full source code&lt;/a&gt; of this example over on GitHub.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>react</category>
      <category>php</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
