<?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: Martin M.</title>
    <description>The latest articles on DEV Community by Martin M. (@skydiver).</description>
    <link>https://dev.to/skydiver</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%2F48807%2Faac35c8b-09e3-42b4-8f63-b8e462c8556f.png</url>
      <title>DEV Community: Martin M.</title>
      <link>https://dev.to/skydiver</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/skydiver"/>
    <language>en</language>
    <item>
      <title>Using Laravel Fortify to restore laravel/ui functionality</title>
      <dc:creator>Martin M.</dc:creator>
      <pubDate>Thu, 17 Sep 2020 01:38:29 +0000</pubDate>
      <link>https://dev.to/skydiver/using-laravel-fortify-to-restore-laravel-ui-functionality-7dc</link>
      <guid>https://dev.to/skydiver/using-laravel-fortify-to-restore-laravel-ui-functionality-7dc</guid>
      <description>&lt;p&gt;Since the release of Laravel 8 and Jetstream, the package &lt;code&gt;laravel/ui&lt;/code&gt; fall in some kind of deprecated status.&lt;/p&gt;

&lt;p&gt;The problem with Jetstream (and i think many of us feel the same) is that we just want the auth scaffolding without the need of Inertia.js or Livewire stacks.&lt;/p&gt;

&lt;p&gt;Don't get me wrong, i love working with Inertia or Livewire, but sometimes you just need the auth part.&lt;/p&gt;

&lt;p&gt;Going back to &lt;code&gt;laravel/ui&lt;/code&gt;, it's still possible to use the package on Laravel 8, but i wanna restore that functionality without mentioned package.&lt;/p&gt;

&lt;p&gt;In the  guide i'm gonna describe all my steps to have a similar behavior using Laravel Fortify.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project setup
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;laravel new laravel-fortify-demo&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;composer require laravel/fortify&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;php artisan vendor:publish --provider="Laravel\\Fortify\\FortifyServiceProvider"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;configure your database&lt;/li&gt;
&lt;li&gt;&lt;code&gt;php artisan migrate&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setup Fortify
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;config/app.php&lt;/code&gt; and register Fortify service provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;App\Providers\FortifyServiceProvider&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, open &lt;code&gt;config/fortify.php&lt;/code&gt; and update your features array as follow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'features'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;Features&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;registration&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nc"&gt;Features&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;resetPasswords&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 we need to tell Fortify where is our auth views.&lt;/p&gt;

&lt;p&gt;Open &lt;code&gt;app/Providers/FortifyServiceProvider.php&lt;/code&gt; and in the &lt;code&gt;boot&lt;/code&gt; method add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Fortify&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;loginView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth.login'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nc"&gt;Fortify&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;registerView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth.register'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nc"&gt;Fortify&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;requestPasswordResetLinkView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth.forgot-password'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nc"&gt;Fortify&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;resetPasswordView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth.reset-password'&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;h2&gt;
  
  
  Create the views
&lt;/h2&gt;

&lt;p&gt;We need to create the 4 mentioned blade files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;resources/views/auth/forgot-password.blade.php&lt;/li&gt;
&lt;li&gt;resources/views/auth/login.blade.php&lt;/li&gt;
&lt;li&gt;resources/views/auth/register.blade.php&lt;/li&gt;
&lt;li&gt;resources/views/auth/reset-password.blade.php&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I "borrowed" the views from the &lt;code&gt;laravel/ui&lt;/code&gt; package; you can grab &lt;a href="https://github.com/skydiver/laravel-fortify-demo/tree/master/resources/views/auth"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Protect your pages
&lt;/h2&gt;

&lt;p&gt;Now we need to protect our routes, open &lt;code&gt;routes/web.php&lt;/code&gt; and use &lt;code&gt;auth&lt;/code&gt; middleware, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'welcome'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'auth'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Final words
&lt;/h2&gt;

&lt;p&gt;As you can see, this article covers the basic register, login and password reset functionalities.&lt;/p&gt;

&lt;p&gt;Fortify includes an interesting email verify feature; if you're interested you can take a look on the package &lt;a href="https://github.com/laravel/fortify#email-verification"&gt;documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind that the auth views (including the bundled css and js files) are made for demo purposes only; you will need to take care of the ui.&lt;/p&gt;

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

&lt;p&gt;If you wanna take a look for the final version, feel free to visit &lt;a href="https://github.com/skydiver/laravel-fortify-demo"&gt;skydiver/laravel-fortify-demo&lt;/a&gt; repo.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>authentication</category>
      <category>auth</category>
      <category>fortify</category>
    </item>
  </channel>
</rss>
