<?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>Forem: Klim Semenov</title>
    <description>The latest articles on Forem by Klim Semenov (@klim).</description>
    <link>https://forem.com/klim</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%2F342608%2F41c8bd02-4769-4562-98c1-ee65880f2b89.jpg</url>
      <title>Forem: Klim Semenov</title>
      <link>https://forem.com/klim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/klim"/>
    <language>en</language>
    <item>
      <title>Installing Laravel and defining routes</title>
      <dc:creator>Klim Semenov</dc:creator>
      <pubDate>Fri, 03 Jul 2020 11:34:45 +0000</pubDate>
      <link>https://forem.com/klim/installing-laravel-and-defining-routes-165k</link>
      <guid>https://forem.com/klim/installing-laravel-and-defining-routes-165k</guid>
      <description>&lt;p&gt;So now, in this second post of building the Laravel website, we will get into actual coding.&lt;/p&gt;

&lt;p&gt;We have 2 main tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing Laravel on Homestead&lt;/li&gt;
&lt;li&gt;Creating 3 view routes for our pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use various local environments while doing Laravel coding. But I prefer &lt;a href="https://laravel.com/docs/7.x/homestead"&gt;Homestead&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this series, we will not cover the Homestead installation process but only use it.&lt;/p&gt;

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

&lt;p&gt;If you didn't start Homestead, run in terminal &lt;code&gt;homestead up&lt;/code&gt; and your pre-configured virtual machine will start.&lt;/p&gt;

&lt;p&gt;For our website, you should configure the &lt;em&gt;Homestead.yaml&lt;/em&gt; file. We are adding a new sync folder, site, and database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;folders:
    - map: ~/vagrant/laravel-catalog
      to: /home/vagrant/laravel-catalog

sites:
    - map: laravel-catalog.test
      to: /home/vagrant/laravel-catalog/public

databases:
    - laravel-catalog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, for our changes to be applied, you need to run:&lt;br&gt;
&lt;code&gt;homestead reload --provision&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;One more step is needed for the correct work of our local website is adding an entry in your hosts file.&lt;/p&gt;

&lt;p&gt;I do it in terminal on my mac machine by editing it with &lt;strong&gt;nano&lt;/strong&gt;. Just type &lt;code&gt;sudo nano /etc/hosts&lt;/code&gt; and add one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;192.168.10.10 laravel-catalog.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, you are ready to install the Laravel framework!&lt;/p&gt;

&lt;p&gt;All you need is just go to your project folder and run:&lt;br&gt;
&lt;code&gt;laravel new&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, if you go to &lt;a href="http://laravel-catalog.test"&gt;http://laravel-catalog.test&lt;/a&gt; in your browser you should see the Laravel welcome page. Congratulations!&lt;/p&gt;

&lt;p&gt;Let's enter some configuration to our &lt;em&gt;.env&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APP_URL=laravel-catalog.test

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=laravel-lidings
DB_USERNAME=homestead
DB_PASSWORD=secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I must mention, that it is more correct to enter &lt;strong&gt;APP_URL&lt;/strong&gt; without http or https. Only the domain. Some Laravel admin panels need such form of configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining Routes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://laravel.com/docs/7.x/routing"&gt;Routes in Laravel&lt;/a&gt; are defined in &lt;em&gt;route/web.php&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::view('/', 'index');
Route::view('/catalog', 'catalog');
Route::view('/product/{code}', 'item');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now, we only use &lt;a href="https://laravel.com/docs/7.x/routing#view-routes"&gt;View Routes&lt;/a&gt;. Because we don't need any logic except displaying our 3 pages. In future posts, we will change this, of course.&lt;/p&gt;

&lt;p&gt;The third route for the item detail page is more complex than others. We capture &lt;strong&gt;{code}&lt;/strong&gt; segment in it. When adding logic to this one, we will use this &lt;strong&gt;code&lt;/strong&gt; variable to get a specific product and display information about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Views for our Pages
&lt;/h2&gt;

&lt;p&gt;Also, we need 3 views for these routes.&lt;/p&gt;

&lt;p&gt;Views are stored in &lt;em&gt;resources/views&lt;/em&gt; directory. We can delete the default &lt;em&gt;welcome.blade.php&lt;/em&gt; (we don't need it).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And create 3 views:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index.blade.php&lt;/li&gt;
&lt;li&gt;catalog.blade.php&lt;/li&gt;
&lt;li&gt;item.blade.php&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just put some default text into them.&lt;/p&gt;

&lt;p&gt;Views in Laravel use &lt;a href="https://laravel.com/docs/7.x/blade"&gt;blade templating engine&lt;/a&gt;. We will cover it while moving to our final website.&lt;/p&gt;

&lt;p&gt;That's it for the second post in our series. All project code is available on &lt;a href="https://github.com/klimsemenov86/laravel-catalog"&gt;github&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>showdev</category>
      <category>homestead</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Starting to build a Laravel simple website</title>
      <dc:creator>Klim Semenov</dc:creator>
      <pubDate>Thu, 02 Jul 2020 11:38:21 +0000</pubDate>
      <link>https://forem.com/klim/starting-to-build-a-laravel-simple-website-5ic</link>
      <guid>https://forem.com/klim/starting-to-build-a-laravel-simple-website-5ic</guid>
      <description>&lt;p&gt;This is the first post of the series, where I will build a Laravel simple website. It will be an items catalog with the admin panel.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://miro.com"&gt;Miro online whiteboard&lt;/a&gt; to design, what will be on the future website.&lt;/p&gt;

&lt;p&gt;Here is the final diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m4mBaHxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h4r09zglh7moqa8lysuh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m4mBaHxP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h4r09zglh7moqa8lysuh.jpg" alt="Miro Board"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's explore it more detailed.&lt;/p&gt;

&lt;p&gt;Our website will consist of 3 pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Index&lt;/li&gt;
&lt;li&gt;Items List&lt;/li&gt;
&lt;li&gt;Items Detail&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The backend framework, that I chose, is &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt;. It is a very popular PHP framework nowadays with &lt;a href="https://laravel.com/docs/7.x"&gt;strong documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The frontend part of the website will be working on &lt;a href="https://andybrewer.github.io/mvp/"&gt;MVP.css&lt;/a&gt;. It is a simple stylesheet for HTML elements with no classes at all. For my purposes, it fits very well. Because my attention will be concentrated on the Laravel framework in this project.&lt;/p&gt;

&lt;p&gt;Also, I want to build a simple administration panel with no additional frameworks or CMS. Of course, we need to protect it with the authorization module. It will be written in pure Laravel. No registration will be supported or social authorization with Facebook or others for the project simplicity.&lt;/p&gt;

&lt;p&gt;Our admin panel will use &lt;a href="https://tailwindcss.com/"&gt;Taiwind CSS&lt;/a&gt; framework, which is extremely popular in the dev community.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Using utility classes to build custom designs without writing CSS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a very &lt;a href="https://tailwindcss.com/docs/utility-first"&gt;useful technique&lt;/a&gt; in case of building an admin panel from scratch.&lt;/p&gt;

&lt;p&gt;So, let's see our final tech stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel (the backend of our website)&lt;/li&gt;
&lt;li&gt;MVP.css (the frontend)&lt;/li&gt;
&lt;li&gt;Tailwind CSS (the admin panel frontend)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>laravel</category>
      <category>showdev</category>
      <category>tailwindcss</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
