<?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: Jerguš Lejko</title>
    <description>The latest articles on DEV Community by Jerguš Lejko (@jerguslejko).</description>
    <link>https://dev.to/jerguslejko</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%2F977%2F4470539.jpeg</url>
      <title>DEV Community: Jerguš Lejko</title>
      <link>https://dev.to/jerguslejko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jerguslejko"/>
    <language>en</language>
    <item>
      <title>Fetching Laravel</title>
      <dc:creator>Jerguš Lejko</dc:creator>
      <pubDate>Thu, 09 Nov 2017 00:00:00 +0000</pubDate>
      <link>https://dev.to/jerguslejko/fetching-laravel-c98</link>
      <guid>https://dev.to/jerguslejko/fetching-laravel-c98</guid>
      <description>&lt;p&gt;&lt;strong&gt;What?&lt;/strong&gt; Last night, shamelessly enough, I spent about 3 hours figuring this out. I was working on a Laravel site that has a concept of “companies”. The &lt;code&gt;companies.index&lt;/code&gt; view simply lists all companies in the database (&lt;em&gt;no pagination&lt;/em&gt;). I wanted to add a search functionality that would update the HTML table as the user types in the query.&lt;/p&gt;

&lt;h1&gt;
  
  
  Issue
&lt;/h1&gt;

&lt;p&gt;When I was sending an AJAX request using the fancy &lt;code&gt;fetch()&lt;/code&gt; API, Laravel would respond with &lt;code&gt;404&lt;/code&gt; without any particular reason. I did not query an API route, neither did I use the &lt;code&gt;api&lt;/code&gt; middleware group. I just wanted to use the same &lt;em&gt;session-based authentication&lt;/em&gt; that I already had in place.&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;Turns out, the &lt;code&gt;fetch()&lt;/code&gt; API does not attach cookies to the request by default. Laravel was receiving a request which could not be identified (no cookies = no session identifier), therefore was not able to recognise the logged in user. In order to send the cookies along with the request, you need to set &lt;code&gt;credentials: 'same-origin'&lt;/code&gt; in the fetch’s configuration object. The call looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, {
    credentials: 'same-origin',
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the request will contain the necessary cookies and the Laravel authentication system will be able to identify the user. 🎉&lt;/p&gt;

</description>
    </item>
    <item>
      <title>(Oh My) ZSH Symfony Completion</title>
      <dc:creator>Jerguš Lejko</dc:creator>
      <pubDate>Tue, 03 Oct 2017 23:00:00 +0000</pubDate>
      <link>https://dev.to/jerguslejko/oh-my-zsh-symfony-completion-139</link>
      <guid>https://dev.to/jerguslejko/oh-my-zsh-symfony-completion-139</guid>
      <description>&lt;p&gt;I am presenting you with my own Oh My Zsh plugin that brings command line autocompletion to your favorite tools such as &lt;code&gt;laravel/artisan&lt;/code&gt;, &lt;code&gt;laravel/valet&lt;/code&gt;, &lt;code&gt;composer&lt;/code&gt; or ANY other command line tool built on &lt;code&gt;symfony/console&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://github.com/jerguslejko/zsh-symfony-completion#oh-my-zsh-symfony-console-completion"&gt;the instructions&lt;/a&gt; on Github and bring life to your command line!&lt;/p&gt;

&lt;h1&gt;
  
  
  Backstory: How &amp;amp; Why
&lt;/h1&gt;

&lt;p&gt;I am a huge fan of &lt;a href="https://github.com/robbyrussell/oh-my-zsh"&gt;Oh My Zsh&lt;/a&gt; and a huge fan of Laravel. When I switched to Oh My Zsh, I have immediately fallen in love with “autocompletion plugins” for various tools such as &lt;code&gt;git&lt;/code&gt; or &lt;code&gt;brew&lt;/code&gt;. However, I was missing this functionality in tools I was using on daily basis: &lt;code&gt;artisan&lt;/code&gt; and &lt;code&gt;composer&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I have googled for suitable plugins but I was not totally satisfied with the ones I found. They were either outdated (new commands missing) or offered only fixed set of commands (it wouldn’t pick up your custom artisan commands). I decided to take a look at how are these plugins structured and come up with a new one that would cover all my needs.&lt;/p&gt;

&lt;p&gt;My first goal was to create an “Artisan completion plugin” that would parse the output of &lt;code&gt;php artisan&lt;/code&gt; and provide me with fully functional autocompletion. I managed to get the prototype working in a few hours and I was pretty happy with the result. Then is struck me! Laravel’s &lt;code&gt;artisan&lt;/code&gt; is built on top of the &lt;code&gt;symfony/console&lt;/code&gt; package. And so is &lt;code&gt;composer&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;I decided to generalize this plugin to support ANY tool built on &lt;code&gt;symfony/console&lt;/code&gt;. That includes &lt;code&gt;laravel/installer&lt;/code&gt; or even &lt;code&gt;laravel/valet&lt;/code&gt;! To activate the autocompletion for your favorite tools, just specify the name of the tool in &lt;code&gt;.zshrc&lt;/code&gt;. Take a look at &lt;a href="https://github.com/jerguslejko/zsh-symfony-completion#instalation"&gt;the Github repository&lt;/a&gt; for further instructions.&lt;/p&gt;

&lt;p&gt;So, here we are. Go ahead, try it and let me know what you think. Thanks.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
