<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MJCoder - Coding To Your Needs]]></title><description><![CDATA[Frontend Web/UI Developer based in Manchester, United Kingdom]]></description><link>https://blog.mjcoder.co.uk</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1707248770879/r8S1u09GK.webp</url><title>MJCoder - Coding To Your Needs</title><link>https://blog.mjcoder.co.uk</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:52:13 GMT</lastBuildDate><atom:link href="https://blog.mjcoder.co.uk/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Magento 2 Index Management is stuck! What do I do now?]]></title><description><![CDATA[Introduction
So I was working away on a website when a support ticket landed on the helpdesk. It was a client complaining that her products on her Magento 2 website had ALL been marked as out of stock. You could sense the panic from the client. Durin...]]></description><link>https://blog.mjcoder.co.uk/magento-2-index-management-is-stuck-what-do-i-do-now</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/magento-2-index-management-is-stuck-what-do-i-do-now</guid><category><![CDATA[Magento]]></category><category><![CDATA[magento 2]]></category><category><![CDATA[ssh]]></category><category><![CDATA[ecommerce]]></category><category><![CDATA[PHP]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Mon, 24 Jan 2022 14:29:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/Tl8mDaue_II/upload/v1643034105860/T8sYZMQ76.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>So I was working away on a website when a support ticket landed on the helpdesk. It was a client complaining that her products on her Magento 2 website had ALL been marked as out of stock. You could sense the panic from the client. During a busy period where stock is selling, this problem just cropped up from out of nowhere.</p>
<h3 id="heading-magento-index-management">Magento Index Management</h3>
<p>Below is a brief description of what index management is and what this does on the website. This is a snippet taken from the Magento User Guide found <a target="_blank" href="https://docs.magento.com/m2/ce/user_guide/system/index-management.html">here</a>;</p>
<blockquote>
<p>Magento reindexes automatically whenever one or more items change. Actions that trigger reindexing include price changes, creating catalog or shopping cart price rules, adding new categories, and so on. To optimize performance, Magento accumulates data into special tables using indexers. As the data changes, the indexed tables must be updated — or reindexed. Reindexing is performed as a background process, and your store remains accessible during the processes.</p>
</blockquote>
<p>So you can see just how important it is for the indexers to be working on the Magento website. If the indexer is not updating stock levels or price rules, it could result in products being sold at the wrong advertised price, some new products not appearing, categories not showing up. Make sure that all the indexer statuses are appearing in green. Below is an example of the indexers appearing fine.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1643034251362/44h9cpgkV.jpeg" alt="1 PUOWRZV64u9UYYPYuc8WeQ.jpeg" /></p>
<h3 id="heading-what-steps-did-you-take-next">What steps did you take next?</h3>
<p>At this point I was left scratching my head, thinking what to do next. The client was manually updating the stock statuses, something that would have taken an age even if there were several people working on the site at one time. My first thought was to run the clean and flush cache commands via SSH.</p>
<p>Here are the commands that were used via SSH;</p>
<pre><code>php bin/magento <span class="hljs-keyword">cache</span>:clean
php <span class="hljs-keyword">bin</span>/magento <span class="hljs-keyword">cache</span>:<span class="hljs-keyword">flush</span>
</code></pre><p>Simple enough right? Not quite! Now at this point, even I started panicking a little. I’m the one that should be calm through this. I guess that wasn’t the case!</p>
<p>Then I decided to run the indexer command, I was confident that this would resolve the problem the client was having with the stock statuses showing as “Out of stock”</p>
<pre><code>php bin/magento indexer:<span class="hljs-keyword">reindex</span>
</code></pre><h3 id="heading-so-did-that-resolve-the-problem-panic-over">So did that resolve the problem, panic over?</h3>
<p>Nope, that did not resolve the problem for the client. At this point, I was scratching my head even harder, any more head-scratching and I’d end up going bald. I kicked the panic to one side, took a deep breath &amp; said to myself that I’m going to resolve this problem before I do anything else.</p>
<p>I came across a command that I didn’t see when looking at the documentation for Magento 2 — I know the commands to clear the cache and flush it from the top of my head, publishing content is fine, running the indexer no problem, but this one command slipped through the net for me. This was the command that would save the hair on my head and kill off the panic for the client.</p>
<pre><code>php bin/magento indexer:<span class="hljs-keyword">reset</span>
</code></pre><p>Oh, you beauty! Running the command in my terminal and flushing the cache sorted this issue out. Turned out that the status column under Index Management was showing as “Processing” for some of the indexers. This is definitely one command I won’t ever forget. It’s etched in my brain now.</p>
<p>I hope this experience will come in handy for someone that may be in the same situation that I was in. Now I can’t guarantee that the problem I came across will be the same one you’ll experience.</p>
<p>I need a coffee now. Phew. Is anyone willing to brew up for me?</p>
]]></content:encoded></item><item><title><![CDATA[7 Awesome WordPress Plugins]]></title><description><![CDATA[What is WordPress?
WordPress is one of the most used Content Management Systems (CMS) out there. Some may argue that it’s a blogging platform, some may argue that it’s more than that. I guess we’ll never come to one agreement on what WordPress really...]]></description><link>https://blog.mjcoder.co.uk/7-awesome-wordpress-plugins</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/7-awesome-wordpress-plugins</guid><category><![CDATA[WordPress]]></category><category><![CDATA[wordpress plugins]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Thu, 20 Jan 2022 14:19:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/ZjX-z2Q5zrk/upload/v1641918038344/D2FF7ACKf.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-wordpress">What is WordPress?</h2>
<p>WordPress is one of the most used Content Management Systems (CMS) out there. Some may argue that it’s a blogging platform, some may argue that it’s more than that. I guess we’ll never come to one agreement on what WordPress really is. All I know is that it’s a brilliant platform to learn &amp; develop on.</p>
<p>I develop quite a few websites in WordPress. It’s open-source and free to use. It comes with a repository of plugins that you can install on WordPress to extend its functionality and do cool stuff. What isn't there to like about that?</p>
<h2 id="heading-advanced-custom-fields-pro-acf-pro">Advanced Custom Fields PRO (ACF Pro)</h2>
<p><a target="_blank" href="https://www.advancedcustomfields.com/">ACF Pro</a> has to be my favourite plugin for WordPress of all time. This allows you to quickly add meta fields, fields to a post, custom post type, post template etc. It’s ideal for custom-built themes in WordPress. You can’t go wrong with this plugin. Not only is this a great plugin to use, but the documentation is also well written, straightforward and understandable, no matter what programming experience you have.</p>
<p>They offer a free version of the plugin which covers most of your needs, but having the PRO version means having those additional fields you can integrate into your WordPress project. Constant updates are also made to the plugin to keep up with the latest changes made by WordPress.</p>
<h2 id="heading-yoast-seo">Yoast SEO</h2>
<p>One of the most used plugins on WordPress for search engine optimisation (SEO) is  <a target="_blank" href="https://yoast.com/wordpress/plugins/seo/">Yoast</a>, there is a premium and free version available. We all want to optimise our website so search engines are able to access it. We all aim to have our websites appear as high as possible in search rankings so it’s more accessible. This is another plugin that provides constant updates on both plans. The UI is fairly simple to use, so for any beginners, you can crack on with optimising pages without the help of an expert.</p>
<blockquote>
<p>Yep, Yoast SEO Premium makes it really easy to seduce search engines. In the free version, you can only set 1 focus keyword. That means you’ll have to choose between keywords. In both versions, Yoast SEO doesn’t only help you boost your ranking in the search results, but also your morale!</p>
</blockquote>
<p>What’s good about the plugin is that it has a built-in preview of what the page will look like once you’ve optimised the description and added keywords. However, most recently I’ve come across another SEO plugin called <a target="_blank" href="https://theseoframework.com/">The SEO Framework</a>. A lightweight plugin that just has the same effect as Yoast SEO.</p>
<h2 id="heading-monster-insights">Monster Insights</h2>
<p>This is another plugin that I use on all WordPress websites. It allows you to enter the Google Analytics tracking code within WordPress which then places the script in the correct part of the website so you can start tracking activity on your website. After all, we all want to know where our users come from, which part of the website they are accessing and how long they are active.</p>
<blockquote>
<p>MonsterInsights is Trusted by Over 1 Million Businesses Worldwide.</p>
</blockquote>
<p>Not only does this <a target="_blank" href="https://www.monsterinsights.com/">Monster Insights</a> allow you to add analytics to the website, it has a built-in dashboard, once approved with your account it shows you stats, just like the Google Analytics dashboard. You can now stop logging into GA to view stats, log into your website instead and see all the information in there.</p>
<h2 id="heading-wordfence-security">Wordfence Security</h2>
<p><a target="_blank" href="https://www.wordfence.com/">Security</a> is essential — we now live in a world where security is a must. With WordPress being targeted by malicious hackers you need some sort of security in place to combat the attacks that take place on a daily basis. Not having the correct security for your website can be catastrophic. Below are some points on what could happen if there is no security on your website;</p>
<ul>
<li>Website hacked/defaced</li>
<li>Database compromised</li>
<li>Malware infecting the website</li>
<li>Stealing credit card information</li>
</ul>
<p>Wordfence Security can combat this for you. They offer premium and free versions. While the free version is more than good enough, you can opt to go premium depending on your security needs.</p>
<p>Wordfence usability is straightforward and very easy to configure. Within a few clicks, you can have Wordfence scanning the website periodically looking for any vulnerabilities or malware. It also allows you to do the following;</p>
<ul>
<li>Web Application Firewall</li>
<li>Real-Time Threat Defense Feed (Premium)</li>
<li>Block Brute Force Attacks</li>
<li>Country Blocking (Premium)</li>
<li>Advanced Manual Blocking</li>
<li>Malware Scanner</li>
</ul>
<p>So you can see you have a vast amount of features available to you. You can also set login notifications, so whenever someone accesses the website you are alerted of this so. It also notifies you of any plugins that are outdated and may need updating. Any files that have been changed will also be picked up. I’ve not had a problem ever using this plugin before. It definitely puts my mind at ease knowing the website is monitored and secure.</p>
<h2 id="heading-ewww-image-optimisation">EWWW Image Optimisation</h2>
<p>Optimising images is a big part of search engine optimisation. It’s really important that images load up quickly on a website no matter where it is accessed from, being a mobile phone or desktop computer. Sites that take more than 3–4 seconds to load will result in the person clicking off your website.</p>
<p>Here are a few of the features EWWW offer;</p>
<ul>
<li>Faster Images</li>
<li>High-Quality Compression</li>
<li>Personal Support</li>
<li>Free Image Backups</li>
</ul>
<p>If you are showcasing products on a website, it’s important that they load as quick as possible, you don’t want potential customers waiting a few minutes for an image to load. This is where <a target="_blank" href="https://ewww.io/">EWWW</a> comes into effect.</p>
<blockquote>
<p>Over 600k Sites Use EWWW IO to Speed Up Their Images</p>
</blockquote>
<p>The need for speed is great. Within a few clicks, you can bulk optimise loads of images that have been uploaded to WordPress and this runs in the background for you. Not long ago, I rebuilt a website for a client that was on WordPress which contained loads of high-resolution images that were not optimised. This affected his page speed load times and the drop off rate was quite high. </p>
<p>The main reason for this was that there were images over 1MB each which was bogging down the website. Running the optimiser worked wonders — not only did the client have optimised images, but the speed of his website was quicker. The page speed was reduced drastically.</p>
<h2 id="heading-wp-fastest-cache">WP Fastest Cache</h2>
<p>With over 6 million downloads and counting, <a target="_blank" href="https://www.wpfastestcache.com/">WP Fastest Cache</a> is one of the go-to plugins for increasing the speed of a website. A host of features are available to you with this plugin, both free and premium.</p>
<ul>
<li>Desktop Cache</li>
<li>Mobile Cache</li>
<li>Widget Cache</li>
<li>Minify HTML</li>
<li>Minify HTML Plus</li>
<li>Minify CSS</li>
<li>Minify CSS Plus</li>
<li>Combine CSS</li>
<li>Minify JS</li>
<li>Combine JS</li>
<li>Combine JS Plus</li>
<li>Render Blocking JS</li>
<li>GZIP</li>
<li>Browser Caching</li>
<li>Image Optimization</li>
<li>Cache Statics</li>
<li>Delete Cache Logs</li>
<li>Database Cleanup</li>
<li>Google Fonts Async</li>
</ul>
<p>If you are not a developer then with a few clicks you can optimise the website and increase the Page Speed dramatically without the need of tinkering with the htaccess file. However you could experience problems based on the theme you are using, if it’s been built quite bad and not followed the WordPress standards then you’ll have a more difficult experience in speeding up the website.</p>
<h2 id="heading-redirection">Redirection</h2>
<p>Another one of my favourite plugins — <a target="_blank" href="https://en-gb.wordpress.org/plugins/redirection/">Redirection</a>. I definitely dislike doing 301 redirects all manually in the htaccess file. With this plugin you can easily create the redirects, manage them with a nice interface and look after any 404 errors you get on the website. </p>
<p>Most of all, it’s free, yes, completely free. This is very useful for someone that has a redeveloped website on a new/existing platform and the URL structure differs. We can keep the old links alive by setting up 301 redirects that direct the user to the new URL all without them knowing that the URL has changed unless they look at the address bar!</p>
<h3 id="heading-there-are-more-plugins-wait-did-you-say-more">There are more plugins, wait, did you say more?</h3>
<p>Yes, there is more. I could sit here all day and list all the plugins that I recommend, but that would put you to sleep. I’ve just touched upon some of the plugins that I use when it comes to WordPress. Let me know what plugins you install on WordPress and why?</p>
]]></content:encoded></item><item><title><![CDATA[Laravel 5.7 — Databases and Migrations]]></title><description><![CDATA[Database Configuration in Laravel
In order to connect a database, we will concentrate on the .env file. This is where you will find the configuration settings to set the database host, username and password along with a host of configurations. You ma...]]></description><link>https://blog.mjcoder.co.uk/laravel-databases-and-migrations</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/laravel-databases-and-migrations</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[data]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Sat, 26 Jan 2019 16:09:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800856761/vNpZS2mA8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-database-configuration-in-laravel">Database Configuration in Laravel</h2>
<p>In order to connect a database, we will concentrate on the <em>.env</em> file. This is where you will find the configuration settings to set the database host, username and password along with a host of configurations. You may never end up using all of them. Below is an example of the .env file that is generated when you create a new Laravel project.</p>
<pre><code>APP\_NAME<span class="hljs-operator">=</span>Laravel

APP\_ENV<span class="hljs-operator">=</span>local

APP\_KEY<span class="hljs-operator">=</span>base64:7b6e1<span class="hljs-operator">+</span>2Ok25kR2g54fVFeEWfXciimtt5eAvBSK7RpWc<span class="hljs-operator">=</span>

APP\_DEBUG<span class="hljs-operator">=</span><span class="hljs-literal">true</span>

APP\_URL<span class="hljs-operator">=</span>http:<span class="hljs-comment">//localhost</span>

LOG\_CHANNEL<span class="hljs-operator">=</span>stack

DB\_CONNECTION<span class="hljs-operator">=</span>mysql

DB\_HOST<span class="hljs-operator">=</span><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>

DB\_PORT<span class="hljs-operator">=</span><span class="hljs-number">3306</span>

DB\_DATABASE<span class="hljs-operator">=</span>homestead

DB\_USERNAME<span class="hljs-operator">=</span>homestead

DB\_PASSWORD<span class="hljs-operator">=</span>secret

BROADCAST\_DRIVER<span class="hljs-operator">=</span>log

CACHE\_DRIVER<span class="hljs-operator">=</span>file

QUEUE\_CONNECTION<span class="hljs-operator">=</span>sync

SESSION\_DRIVER<span class="hljs-operator">=</span>file

SESSION\_LIFETIME<span class="hljs-operator">=</span><span class="hljs-number">120</span>

REDIS\_HOST<span class="hljs-operator">=</span><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>

REDIS\_PASSWORD<span class="hljs-operator">=</span>null

REDIS\_PORT<span class="hljs-operator">=</span><span class="hljs-number">6379</span>

MAIL\_DRIVER<span class="hljs-operator">=</span>smtp

MAIL\_HOST<span class="hljs-operator">=</span>smtp.mailtrap.io

MAIL\_PORT<span class="hljs-operator">=</span><span class="hljs-number">2525</span>

MAIL\_USERNAME<span class="hljs-operator">=</span>null

MAIL\_PASSWORD<span class="hljs-operator">=</span>null

MAIL\_ENCRYPTION<span class="hljs-operator">=</span>null

PUSHER\_APP\_ID<span class="hljs-operator">=</span>

PUSHER\_APP\_KEY<span class="hljs-operator">=</span>

PUSHER\_APP\_SECRET<span class="hljs-operator">=</span>

PUSHER\_APP\_CLUSTER<span class="hljs-operator">=</span>mt1

MIX\_PUSHER\_APP\_KEY<span class="hljs-operator">=</span>”${PUSHER\_APP\_KEY}”

MIX\_PUSHER\_APP\_CLUSTER<span class="hljs-operator">=</span>”${PUSHER\_APP\_CLUSTER}”
</code></pre><p>The only part of the .env file we need to focus on is the MySQL configuration. We need to create the database using PHPMyAdmin or SQL Workbench. Then enter populate the following fields.</p>
<pre><code>DB\_CONNECTION<span class="hljs-operator">=</span>mysql  
DB\_HOST<span class="hljs-operator">=</span><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>  
DB\_PORT<span class="hljs-operator">=</span><span class="hljs-number">3306</span>  
DB\_DATABASE<span class="hljs-operator">=</span>database<span class="hljs-operator">-</span>name<span class="hljs-operator">-</span>here  
DB\_USERNAME<span class="hljs-operator">=</span>username<span class="hljs-operator">-</span>here  
DB\_PASSWORD<span class="hljs-operator">=</span>your<span class="hljs-operator">-</span>password<span class="hljs-operator">-</span>here
</code></pre><p>There’s also a database.php file that can be found inside the config folder. This file shows you the different database connections you can make. For now, we will use the default MySQL connection. That is good enough. You can see the file here on the official Laravel Github repository: <a target="_blank" href="https://github.com/laravel/laravel/blob/master/config/database.php">https://github.com/laravel/laravel/blob/master/config/database.php</a></p>
<h3 id="heading-database-migrations">Database Migrations</h3>
<p>In order to create a migration in Laravel we use the following command;</p>
<pre><code><span class="hljs-attribute">php</span> artisan migrate
</code></pre><p>Once you run this command it will create the users &amp; password reset tables. By default, it also creates a migration table where it’ll store every single migration you make. You should never tinker with this table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800849938/KF6ddJ5_N.png" alt /></p>
<p>Here are the default migration files that come with Laravel out of the box.</p>
<p>Let’s have a quick look at the migration file and what it’s doing once the migrate command is run in our terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800851124/KFtdtsVlY.png" alt /></p>
<p>So in the up function, this is where the fields are specified. It’s all pretty straightforward. When we run the migrate the command, the up function is executed and the table is created inside our database. If you’ve run the migrate command successfully, head over to the database that you’ve created, give it a refresh and take a look at the tables that have been created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800852484/w9FvOEL2U.png" alt /></p>
<p>As you can see, the columns have been created which reflects the user migration file.</p>
<p>What if we want to delete the table? Can we do this through PHPMyAdmin or Workbench? Yes, we can do that, but if there is a command for it, why not use that? We must get into the habit of using the Artisan commands that are available to us, it will save you loads of time, trust me!</p>
<pre><code>php artisan migrate:<span class="hljs-keyword">reset</span>
</code></pre><p>The above command will reset the migration for you, there is also the rollback command that rolls back the LAST migration you ran. So that is why it’s important we don’t tinker with the migrations database and the files that are created in the migrations folder. We require these.</p>
<p>There is another command that we can also run, but it’s very important that you only use it in the local environment and not on a live server/project.</p>
<pre><code><span class="hljs-selector-tag">php</span> <span class="hljs-selector-tag">artisan</span> <span class="hljs-selector-tag">migrate</span><span class="hljs-selector-pseudo">:fresh</span>
</code></pre><p>The <code>migrate:fresh</code> command will drop all tables from the database and then execute the <code>migrate</code> command.</p>
<h3 id="heading-creating-a-migration">Creating a migration</h3>
<p>To create a migration, we can use the <strong>make:migration</strong> command. This will create the PHP file inside our migrations folder.</p>
<pre><code>php artisan make:migration <span class="hljs-keyword">create</span>\_tasks\_table
</code></pre><p>We now have a migration file created, open up that file and let's start adding some fields to it. What I’m going to do is add a title and description field to our database. A task will have a title &amp; a description.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800853743/MzNHBMxmZ.png" alt /></p>
<p>Title and Description have been added to the migration file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800855031/hQ0owHegI.png" alt /></p>
<p>We now have a title and description field when we ran the migrate command.</p>
<p>If you want to make a change to the migration file without deleting the table, we can run the following command;</p>
<pre><code><span class="hljs-selector-tag">php</span> <span class="hljs-selector-tag">artisan</span> <span class="hljs-selector-tag">migrate</span><span class="hljs-selector-pseudo">:fresh</span>
</code></pre><p>This will run ALL migrations again. You can find out more information on the Laravel documentation: <a target="_blank" href="https://laravel.com/docs/5.7/migrations#running-migrations">https://laravel.com/docs/5.7/migrations#running-migrations</a></p>
<p>In the next article, I will show you how to insert data into the table and how we can query this in our Laravel project.</p>
<p>I hope you’ve enjoyed this article, give it a share. If you have any comments, feel free to use the comments section or get in touch with me on my Twitter. Don’t forget to have a look at my previous articles.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel 5.7 — Controllers]]></title><description><![CDATA[Here is a perfect breakdown on what a Laravel Controller is taken from the official Laravel documentation;

Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller cla...]]></description><link>https://blog.mjcoder.co.uk/laravel-controllers</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/laravel-controllers</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[mvc]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Sun, 23 Dec 2018 11:46:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800867115/-BHKcR-dE.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here is a perfect breakdown on what a Laravel Controller is taken from the official Laravel documentation;</p>
<blockquote>
<p>Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the <code>**app/Http/Controllers**</code> directory.</p>
</blockquote>
<p>In our routes file, we may want to add more logic to a view, this could get tiresome with loads of code showing. We want to simplify how we work, Laravel allows us to do that, we can use a dedicated controller to add more logic to our routes/views.</p>
<p>If you take a look at the routes file in your editor, each page is static, so what we can do is create a Pages Controller — we can simplify the code more by using the controller we are about to create.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800860709/9eDaE5kTO.png" alt /></p>
<p>So let’s start with the homepage route, we need to create a new line in our routes file and define the Pages Controller followed by a method/action. If your getting confused now, hang in there, this will become clearer to you shortly.</p>
<pre><code><span class="hljs-attribute">Route</span>::get(‘/’, ‘PagesController<span class="hljs-variable">@home</span>’);
</code></pre><p>Comment out the code for the homepage route that has the array of tasks, reload the homepage and you should see the following error;</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800862801/diO9UGnVl.png" alt /></p>
<p>Oops, we’ve not created the “PagesController” — Laravel is looking for this and can’t find it, this is easy to fix. Head over to your terminal and run the following command to create the controller.</p>
<pre><code>$ php artisan <span class="hljs-built_in">make</span>:controller PagesController
</code></pre><p>What we must not do is create the controller manually, Laravel offers the boilerplate to you, it whips up the necessary code when you create the controller through the command line. Let’s get into the habit of using the terminal and running the necessary commands, the more you use the commands, the more it’ll sit in your brain for future reference.</p>
<p>You will find the controller inside <code>app/http/controllers/</code> — this is where the controllers live in Laravel. This is what the Pages Controller looks like once it has been created;</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="&lt;?php

namespace App\\Http\\Controllers;

use Illuminate\\Http\\Request;

class PagesController extends Controller {  
   //  
}"></a></div>
<p>You can see why it was much simpler to run the command to create the controller. We wouldn't want to be importing the namespace etc manually in case we need to.</p>
<p>Let’s create a method for home, otherwise, the PagesController will not work.</p>
<pre><code><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">home</span>(<span class="hljs-params"></span>) </span>{

}
</code></pre><p>We now need to migrate the data from the old route we initially had into the method we have just created. Delete the old route for the homepage as we won’t be needing that moving forward. This is what the end result should look once you’ve migrated over the data to the method.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800864186/Bo3oyWguJ.png" alt /></p>
<p>We can now migrate the rest of the routes over to the Pages Controller. We need to copy the same line where we called the home method and name the methods as the page name. This is to keep some consistency and quickly identify each method. Our routes file should now look something like this;</p>
<pre><code><span class="hljs-attribute">Route</span>::get(‘/’, ‘PagesController<span class="hljs-variable">@home</span>’);;

<span class="hljs-attribute">Route</span>::get(‘/about’, ‘PagesController<span class="hljs-variable">@about</span>’);;

<span class="hljs-attribute">Route</span>::get(‘/contact’, ‘PagesController<span class="hljs-variable">@contact</span>’);
</code></pre><p>And here we have the Pages Controller with two additional methods added that return the view. If you’ve followed the steps correctly, then the homepage and the other pages should be working just like they did without the Pages Controller created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800865572/5L5DvyLLB.png" alt /></p>
<p>So for any large projects that you may be working on, this is the ideal way to go about things, you may come across existing projects that follow this structure. This keeps things nicely separated.</p>
<p>That’s it, you now should understand how to use dedicated controllers in Laravel. In the next article, we will be looking at <strong>“Databases and Migrations”.</strong></p>
<p>I hope you’ve enjoyed this article, give it a share. If you have any comments, feel free to use the comments section or get in touch with me on my Twitter. Don’t forget to have a look at my previous articles.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel  5.7 —  Sending Data to Your Views]]></title><description><![CDATA[How to send data to your view
This article will show you how to send data to your Laravel view. So let’s get started. For example, let’s say when a user accesses the homepage, we want to send some data to it for them to view. Head over into your code...]]></description><link>https://blog.mjcoder.co.uk/laravel-sending-data-to-your-views</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/laravel-sending-data-to-your-views</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[mvc]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Sat, 22 Dec 2018 14:15:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800874338/57xECfNK5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-how-to-send-data-to-your-view">How to send data to your view</h2>
<p>This article will show you how to send data to your Laravel view. So let’s get started. For example, let’s say when a user accesses the homepage, we want to send some data to it for them to view. Head over into your code editor and go to <code>routes/web.php</code> — this is where we will be passing in the data for now by hardcoding it in.</p>
<p>Inside the route get for the homepage we need to create a variable and pass in some tasks as an array. So take a look at the code below to see the tasks that have been created.</p>
<pre><code>Route::get(‘<span class="hljs-operator">/</span>’, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{

$tasks <span class="hljs-operator">=</span> \[  
    ‘Build header of the website’,  
    ‘Build footer of the website’,  
    ‘Build the homepage template’,  
\];

<span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’);

});
</code></pre><p>If we access the homepage, nothing is going to happen in regards to the tasks data being passed through. We haven't returned this yet. Next, you need to call tasks in the return function.</p>
<pre><code><span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’, \[  
    ‘tasks’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> $tasks  
\]);
</code></pre><h3 id="heading-rendering-data-in-the-view">Rendering data in the view</h3>
<p>Remember to pass this in as an array. We’re nearly there, head over to the <strong><em>welcome.blade.php</em></strong> file and inside a foreach loop, we will render the tasks that we’ve hardcoded in.</p>
<pre><code><span class="hljs-operator">&lt;</span>ul class<span class="hljs-operator">=</span>”tasks<span class="hljs-operator">-</span>list”<span class="hljs-operator">&gt;</span>  
@foreach ($tasks <span class="hljs-keyword">as</span> $task)  
    <span class="hljs-operator">&lt;</span>li class<span class="hljs-operator">=</span>”task<span class="hljs-operator">-</span>item”<span class="hljs-operator">&gt;</span><span class="hljs-operator">&lt;</span>?<span class="hljs-operator">=</span> $task ?<span class="hljs-operator">&gt;</span><span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>li<span class="hljs-operator">&gt;</span>  
@endforeach  
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>ul<span class="hljs-operator">&gt;</span>
</code></pre><p>Remember to use the blade syntax and not the standard <strong>PHP</strong> foreach loop. Either way will work, but it’s best to get accustomed to the correct syntax when using Laravel. So here we are cycling through the array of tasks that have been assigned to the <code>$tasks</code> variable &amp; rendering those items into an unordered list. </p>
<p>Here is the outcome when you reload the homepage.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800870678/sWvWCFqxb.png" alt /></p>
<p>The tasks list has now been passed into the homepage view.</p>
<p>If you add another task to the array in the routes file, that will show up here. Fairly simple isn’t it? We can also change the way we call out the <code>$task</code> in the list without using the PHP shorthand syntax;</p>
<pre><code><span class="hljs-operator">&lt;</span>li class<span class="hljs-operator">=</span>”task<span class="hljs-operator">-</span>item”<span class="hljs-operator">&gt;</span>{{ $task }}<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>li<span class="hljs-operator">&gt;</span>
</code></pre><p>We’ve now replaced <code>&lt;?= ?&gt;</code> with the double curly braces. I prefer this, it just looks loads cleaner and easier to read. Always look at ways to simplify the code if you can.</p>
<h3 id="heading-passing-variables-in-to-your-view">Passing variables in to your view</h3>
<p>We can also pass in as many variables as we want when we are returning the tasks on the homepage view. We just need to add another line of code and then call the variable in our blade file.</p>
<pre><code><span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’, \[  
    ‘tasks’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> $tasks,  
    ‘sitename’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> ‘Laravel’  
\]);
</code></pre><p>I’ve just created a variable called <code>sitename</code> for now. In the blade file, this is how I’ve called that variable.</p>
<pre><code><span class="hljs-operator">&lt;</span>h1<span class="hljs-operator">&gt;</span>{{ $sitename }} — Homepage<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h1<span class="hljs-operator">&gt;</span>
</code></pre><p>Simple and straightforward. Don’t you just love it? We can fetch anything from the query string, let me show you how to do this. We ain’t finished just yet. There’s more goodness to showcase here. Let’s create a request;</p>
<pre><code>‘title’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> request(‘title’)
</code></pre><p>We now need to go back to the homepage and enter the following into the URL after the homepage URL.</p>
<pre><code><span class="hljs-attribute">http</span>:<span class="hljs-comment">//laracasts.local/?title=Laracasts</span>
</code></pre><p>So what happens when you pass in the word Laracasts? Below is the result of requesting something from the query string;</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800871848/8lErY5m8U.png" alt /></p>
<p>We’ve requested the title Laracasts and rendered that on the page.</p>
<p>The curly braces in Laravel escape the data and render what’s left on the page. This is brilliant, we want to make sure no malicious data is being passed through. For example, if we try passing in script tags into the variable that we have created, do you think that will render a script on the page?</p>
<pre><code>‘title’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> ‘<span class="hljs-operator">&lt;</span>script<span class="hljs-operator">&gt;</span>alert(“Hello — I love laravel”)<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>script<span class="hljs-operator">&gt;</span>’
</code></pre><p>The outcome is that the script was not executed as a script, whatever was passed into the variable has been stripped out.</p>
<pre><code><span class="hljs-operator">&lt;</span>h1<span class="hljs-operator">&gt;</span><span class="hljs-operator">&amp;</span>lt;script<span class="hljs-operator">&amp;</span>gt;alert(<span class="hljs-operator">&amp;</span>quot;Hello — I love laravel<span class="hljs-operator">&amp;</span>quot;)<span class="hljs-operator">&amp;</span>lt;<span class="hljs-operator">/</span>script<span class="hljs-operator">&amp;</span>gt; — Homepage<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h1<span class="hljs-operator">&gt;</span>
</code></pre><p>And there you have it, the script has been stripped down and rendered. So you may ask, how do I make sure a script acts as a script? We can use <code>!!</code> exclamation points on either side of the curly braces. This is what it should look like.</p>
<pre><code><span class="hljs-operator">&lt;</span>h1<span class="hljs-operator">&gt;</span>{{<span class="hljs-operator">!</span><span class="hljs-operator">!</span> $title <span class="hljs-operator">!</span><span class="hljs-operator">!</span>}} — Homepage<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h1<span class="hljs-operator">&gt;</span>
</code></pre><p>If you refresh the homepage now, the script will be initialised and will successfully run.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800873062/YhsOa6yUk.png" alt /></p>
<p>Voila — our script alert is now working!</p>
<p>I’ve mentioned that we should always look at ways to simplify our code. When we are returning the tasks variable to our view, it looks a little messy to me. We can pass that data to our view with one line of code, yes, just one!</p>
<pre><code><span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’, \[  
    ‘tasks’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> $tasks,  
    ‘title’ <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> request(‘title’)  
\]);
</code></pre><p>The above code is now going to be simplified into one line.</p>
<pre><code><span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’)<span class="hljs-operator">-</span><span class="hljs-operator">&gt;</span>withTasks($tasks)<span class="hljs-operator">-</span><span class="hljs-operator">&gt;</span>withTitle(<span class="hljs-string">'`Laracasts`'</span>);
</code></pre><p>We can pass in the two functions and within those pass in the variable &amp; string. We can inline the tasks in the return function if you want to. There are different ways we can pass in the tasks.</p>
<pre><code>Route::get(‘<span class="hljs-operator">/</span>’, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{  
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’)<span class="hljs-operator">-</span><span class="hljs-operator">&gt;</span>withTasks(\[  
        ‘Build header of the website’,  
        ‘Build footer of the website’,  
        ‘Build the homepage template’,  
        ‘Build the contact form’,  
    \]);  
});
</code></pre><p>I prefer this way. Whichever way works for you that’s fine, there is no right or wrong way.</p>
<h3 id="heading-using-compact-in-laravel">Using compact() in Laravel</h3>
<p>The function compact is widely used in Laravel, don’t confuse this with a Laravel function because it’s not, this is a PHP function. You can see more information on this over <a target="_blank" href="http://php.net/compact">HERE</a>. So <code>with()</code> allows you to pass variables to a view and <code>compact()</code> creates an array from existing variables given as string arguments to it.</p>
<p>Below is an example of how we’d use the compact function.</p>
<pre><code>$user = User::all();   
<span class="hljs-keyword">return</span> view(<span class="hljs-string">'index'</span>, compact(<span class="hljs-string">'user'</span>));
</code></pre><p>Here is another example where we are passing the name into our view surrounded by HTML. This will output the name <strong>Joe Bloggs</strong> on the home view.</p>
<pre><code>Route::get(<span class="hljs-string">'/'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{  
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(<span class="hljs-string">'greeting'</span>, compact([<span class="hljs-string">'name'</span> <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> <span class="hljs-string">'Joe Bloggs'</span>]));  
});  
<span class="hljs-operator">&lt;</span>html<span class="hljs-operator">&gt;</span>  
    <span class="hljs-operator">&lt;</span>body<span class="hljs-operator">&gt;</span>  
        <span class="hljs-operator">&lt;</span>h1<span class="hljs-operator">&gt;</span>Hello, {{ $name }}<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>h1<span class="hljs-operator">&gt;</span>  
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>body<span class="hljs-operator">&gt;</span>  
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>html<span class="hljs-operator">&gt;</span>
</code></pre><p>That’s it, you now should understand how to send data to your views. In the next article, we will be looking at <strong>“Controllers”.</strong> I hope you’ve enjoyed this article, give it a share. If you have any comments, feel free to use the comments section or get in touch with me on my Twitter. Don’t forget to have a look at my previous articles.</p>
<p>Thank you.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel 5.7 — Blade Layout Files]]></title><description><![CDATA[In this article, I will discuss how you should use blade layout files, Blade is driven by template inheritance and sections. It really is a great way in pulling certain layouts/content into a view. This makes sure you are not copying & pasting the sa...]]></description><link>https://blog.mjcoder.co.uk/laravel-blade-layout-files</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/laravel-blade-layout-files</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[mvc]]></category><category><![CDATA[SEO]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Fri, 14 Dec 2018 09:31:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800879250/i8eAfEK7X.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, I will discuss how you should use blade layout files, Blade is driven by template inheritance and sections. It really is a great way in pulling certain layouts/content into a view. This makes sure you are not copying &amp; pasting the same code into multiple views. Imagine you have to make one change in the source code, do you really want to go through every single view and update the source code? No, we don’t. That is not the best practice.</p>
<h4 id="heading-creating-a-layout-file">CREATING A LAYOUT FILE</h4>
<p>Head over into your code editor and go into <em>/resources/views/</em> and create a new file called <strong>layout.blade.php.</strong> Remember to add the word blade into the filename, otherwise, it won’t work.</p>
<p>Once you’ve created the layout file, copy and paste the HTML from the <strong>welcome.blade.php</strong> view and into the layout file. The HTML that we will move over is shown below;</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800877823/JIuMmoPxs.png" alt /></p>
<p>The HTML that has been added to the layout.blade.php file</p>
<p>Once you’ve done that, we need to add in the following code into the layout file;</p>
<pre><code><span class="hljs-variable">@yield</span>(‘content’);
</code></pre><p>Here we are telling Laravel to render the content. Go back to welcome.blade.php and delete everything that is in it. For now, we will add this bit of code in the view file.</p>
<pre><code><span class="hljs-meta">@extends(‘layout’)</span>
</code></pre><p>We are telling Laravel to look into the views folder and locate the layout blade file that we created, whatever is inside that file will be rendered on the homepage. I’ve added in two links, one for the homepage, the other to the about page. This is how it will show on the homepage.</p>
<p>If you wish to do so, you could even create a layout direct inside the views folder. If you go down this route, no pun intended, then you would have to reference the layout file using the following;</p>
<pre><code><span class="hljs-meta">@extends(‘layouts.layout’)</span>
</code></pre><p>Notice that we have used the ‘.’ to separate the directories. You could replace the period with a ‘/’ but I think it looks better visually with the period. For now, I’m going to keep the layout file where it is.</p>
<p>We now need to register a section, further up, we added the yield code into the template, but there is no section for it, so nothing will be rendered. To register a section we need to add the following to our template file;</p>
<pre><code><span class="hljs-variable">@section</span>(‘content’)  
   &lt;p&gt;This is the content.&lt;/p&gt;  
<span class="hljs-variable">@endsection</span>
</code></pre><p>Refresh the homepage and it’ll show you the content you have added. Remember, we need to use the blade syntax here. For every section you create, you must remember to add <code>@endsection</code>otherwise you’ll run into problems.</p>
<p>Remember, wherever you add the yield content snippet of code, Laravel will render the content there. So please, make sure you add it to a sensible place, for example, below the navigation and not above it.</p>
<h4 id="heading-title-tags-how-can-we-set-this">TITLE TAGS — HOW CAN WE SET THIS?</h4>
<p>If you take a look at the tab in your browser, you will notice that the page title is currently showing the URL. Now, that looks messy, doesn't it? It’s not really SEO friendly — so we need to get that changed. Let me show you how you can achieve this.</p>
<p>If you take a look at the<code>&lt;title&gt;&lt;/title&gt;</code> it’s currently empty. We need to set something here. We simply cannot go to the layout file and hardcode some text in there. Otherwise, this will display on ALL pages. It needs to be dynamic.</p>
<p>To get the title working, we need to add the following snippet of code;</p>
<pre><code><span class="hljs-meta">@yield(‘title’)</span>
</code></pre><p>We then need to create a section called title in order for this to pull the title that we will set in the view template.</p>
<pre><code><span class="hljs-variable">@section</span>(‘title’)  
    Home  
<span class="hljs-variable">@endsection</span>
</code></pre><p>It’s as easy as that. But what happens if we don’t define a section called title? If we don’t have a section, it will default back to the title, so we need to put something in place for that scenario. Take a look at the following snippet of code where we will be setting a fallback.</p>
<pre><code><span class="hljs-operator">&lt;</span>title<span class="hljs-operator">&gt;</span>@yield(‘title’, ‘Default Title’)<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>title<span class="hljs-operator">&gt;</span>
</code></pre><p>We set a second value after the title using a comma. So if the section title is not defined in the view template, it will render “Default Title”. Think of it as an if-else statement.</p>
<p>We can simplify the title when we define the section. Have a look at this snippet of code;</p>
<pre><code><span class="hljs-meta">@section(‘title’, ‘Home’)</span>
</code></pre><p>That looks loads better, easier to read and we can get the code onto one line. Always look at ways to shorten the code and markup if possible. Either way is fine, I just prefer it this way.</p>
<p>That’s it, you now should understand how blade layout files work and how we can set a dynamic page title for our view. In the next article, we will be looking at “Sending Data to Your Views”. </p>
<p>I hope you’ve enjoyed this article, give it a share. If you have any comments, feel free to use the comments section or get in touch with me on my Twitter.</p>
<p>Thank you.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel 5.7 — Basic Routing]]></title><description><![CDATA[So now you are wondering how do I get into Laravel and build some pages and URLs. Well by the end of this article you will leave knowing what basic routing is and how to get it up and running in your project.
But before diving right into the deep end...]]></description><link>https://blog.mjcoder.co.uk/laravel-basic-routing</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/laravel-basic-routing</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[mvc]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Thu, 13 Dec 2018 10:31:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800895670/6lqzlxNzX.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>So now you are wondering how do I get into Laravel and build some pages and URLs. Well by the end of this article you will leave knowing what basic routing is and how to get it up and running in your project.</p>
<p>But before diving right into the deep end and drowning, let’s take a look at some of the commands that will be used. In the terminal enter the following command;</p>
<pre><code><span class="hljs-attribute">php</span> artisan
</code></pre><p>Artisan is the built-in command into Laravel, this will give you a list of all the commands that are available to you, don’t worry though, some of the commands will make sense once you start using them. Below is a list of the commands that show up once that command has been executed.</p>
<p>Usage:<br /> command [options] [arguments]</p>
<p>Options:<br /> -h, — help Display this help message<br /> -q, — quiet Do not output any message<br /> -V, — version Display this application version<br /> — ansi Force ANSI output<br /> — no-ansi Disable ANSI output<br /> -n, — no-interaction Do not ask any interactive question<br /> — env[=ENV] The environment the command should run under<br /> -v|vv|vvv, — verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</p>
<p>Available commands:  </p>
<p>clear-compiled Remove the compiled class file<br /> down Put the application into maintenance mode<br /> dump-server Start the dump server to collect dump information.<br /> env Display the current framework environment<br /> help Displays help for a command<br /> inspire Display an inspiring quote<br /> list Lists commands<br /> migrate Run the database migrations<br /> optimize Cache the framework bootstrap files<br /> preset Swap the front-end scaffolding for the application<br /> serve Serve the application on the PHP development server<br /> tinker Interact with your application<br /> up Bring the application out of maintenance mode</p>
<p><strong>app  </strong>
app:name Set the application namespace<br />auth<br />auth:clear-resets Flush expired password reset tokens  </p>
<p><strong>cache </strong> 
 cache:clear Flush the application cache<br /> cache:forget Remove an item from the cache<br /> cache:table Create a migration for the cache database table<br /> config<br /> config:cache Create a cache file for faster configuration loading<br /> config:clear Remove the configuration cache file</p>
<p><strong>db  </strong>
 db:seed Seed the database with records</p>
<p><strong>event </strong> 
 event:generate Generate the missing events and listeners based on registration</p>
<p><strong>key </strong> 
 key:generate Set the application key  </p>
<p><strong>make  </strong>
 make:auth Scaffold basic login and registration views and routes<br /> make:channel Create a new channel class<br /> make:command Create a new Artisan command<br /> make:controller Create a new controller class<br /> make:event Create a new event class<br /> make:exception Create a new custom exception class<br /> make:factory Create a new model factory<br /> make:job Create a new job class<br /> make:listener Create a new event listener class<br /> make:mail Create a new email class<br /> make:middleware Create a new middleware class<br /> make:migration Create a new migration file<br /> make:model Create a new Eloquent model class<br /> make:notification Create a new notification class<br /> make:observer Create a new observer class<br /> make:policy Create a new policy class<br /> make:provider Create a new service provider class<br /> make:request Create a new form request class<br /> make:resource Create a new resource<br /> make:rule Create a new validation rule<br /> make:seeder Create a new seeder class<br /> make:test Create a new test class  </p>
<p><strong>migrate  </strong>
 migrate:fresh Drop all tables and re-run all migrations<br /> migrate:install Create the migration repository<br /> migrate:refresh Reset and re-run all migrations<br /> migrate:reset Rollback all database migrations<br /> migrate:rollback Rollback the last database migration<br /> migrate:status Show the status of each migration  </p>
<p><strong>notifications  </strong>
 notifications:table Create a migration for the notifications table  </p>
<p><strong>optimize</strong><br /> optimize:clear Remove the cached bootstrap files  </p>
<p><strong>package  </strong>
 package:discover Rebuild the cached package manifest  </p>
<p><strong>queue  </strong>
 queue:failed List all of the failed queue jobs<br /> queue:failed-table Create a migration for the failed queue jobs </p>
<p><strong>database table </strong> 
 queue:flush Flush all of the failed queue jobs<br /> queue:forget Delete a failed queue job<br /> queue:listen Listen to a given queue<br /> queue:restart Restart queue worker daemons after their current job<br /> queue:retry Retry a failed queue job<br /> queue:table Create a migration for the queue jobs database table<br /> queue:work Start processing jobs on the queue as a daemon  </p>
<p><strong>route  </strong>
 route:cache Create a route cache file for faster route registration<br /> route:clear Remove the route cache file<br /> route:list List all registered routes  </p>
<p><strong>schedule  </strong>
 schedule:finish Handle the completion of a scheduled command<br /> schedule:run Run the scheduled commands  </p>
<p><strong>session  </strong>
 session:table Create a migration for the session database table<br /> storage<br /> storage:link Create a symbolic link from “public/storage” to “storage/app/public”  </p>
<p><strong>vendor  </strong>
 vendor:publish Publish any publishable assets from vendor packages  </p>
<p><strong>view  </strong>
 view:cache Compile all of the application’s Blade templates<br /> view:clear Clear all compiled view files</p>
<p>There are quite a few commands but don’t worry at all, you may not end up using all of them.</p>
<p>In the early steps of using Laravel for the first time, you will end up spending most of your time in <code>routes/web.php</code></p>
<p>Let’s take a look at the web.php file in your code editor. With some basic understanding of programming, you should be able to tell quite quickly what the route is doing.</p>
<pre><code>Route::get(‘<span class="hljs-operator">/</span>’, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{  
   <span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘welcome’);  
});
</code></pre><p>So Laravel is telling the browser to make a GET request, the <em>‘/’</em> is the homepage URL and we then tell the function to return the view <em>‘welcome’.</em> Sounds very simple, doesn't it?</p>
<p>Here is some basic information on routing from the official <a target="_blank" href="https://laravel.com/docs/5.7/routing">Laravel website</a>;</p>
<blockquote>
<p>All Laravel routes are defined in your route files, which are located in the <code>routes</code> directory. These files are automatically loaded by the framework. The <code>routes/web.php</code> file defines routes that are for your web interface. These routes are assigned the <code>web</code> middleware group, which provides features like session state and CSRF protection. The routes in <code>routes/api.php</code> are stateless and are assigned the <code>api</code> middleware group.</p>
<p>For most applications, you will begin by defining routes in your <code>routes/web.php</code> file. The routes defined in <code>routes/web.php</code> may be accessed by entering the defined route's URL in your browser. For example, you may access the following route by navigating to <code>http://your-app.test/user</code> in your browser</p>
</blockquote>
<h4 id="heading-editing-the-welcome-page">EDITING THE WELCOME PAGE</h4>
<p>To get to the welcome page, you will need to go to /<strong>resources/views/welcome.blade.php</strong></p>
<p>This is where you will find the HTML and styling for the page. Let’s update the heading “Laravel” to “Learning Laravel”.</p>
<pre><code><span class="hljs-operator">&lt;</span>div class<span class="hljs-operator">=</span>”title m<span class="hljs-operator">-</span>b<span class="hljs-operator">-</span>md”<span class="hljs-operator">&gt;</span>Learning Laravel<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
</code></pre><p>Now refresh the page in the browser to see if that change has been reflected.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800891867/QeT1J_qRn.png" alt /></p>
<p>The title has now been updated after making the change in the source code</p>
<p>Voila — you have now mastered the first step in locating a view and making a change to it that is reflected in the browser. Give yourself a pat on the back!</p>
<iframe src="https://giphy.com/embed/7rj2ZgttvgomY/twitter/iframe" width="435" height="249"></iframe>

<h4 id="heading-creating-your-own-route">CREATING YOUR OWN ROUTE</h4>
<p>Let’s finish off by creating a route of our own, head over back to <strong>/routes/web.php</strong> copy the current route and set a URL and a view for it to return. Let me show you how to create an about route inside the file.</p>
<pre><code>Route::get(‘<span class="hljs-operator">/</span>about’, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{  
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">view</span>(‘about’);  
});
</code></pre><p>We are telling the route to get the following URL which is /about and then to return a view called ‘about’. It’s good practice to keep the name of the URL and View the same to avoid any confusion. It wouldn't make sense if you had a URL ‘about’ and the view was called ‘random’.</p>
<p>Try navigating to /about in the browser? Oops! What’s gone on here?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800893158/36zqxDutc.png" alt /></p>
<p>View not found error in Laravel</p>
<p>Laravel is telling us that there is no <strong>view</strong> about created so it cannot, therefore, load it. Go back to your project folder, head over into <strong>/resources/views/</strong> and create a file called <strong>about.blade.php.</strong> You have to include the word blade when creating a view as it’s Laravel templating engine that is being used to render the file.</p>
<p>Once that has been created, add some HTML to the page and then reload the page in the browser, this will get rid of the error message and return the HTML for the about page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800894424/PkGZj2gxZ.png" alt /></p>
<p>There you go — the about page is now accessible and working!</p>
<p>We now need to set up a navigation of links so we can access the homepage and the about page. Go to the <strong>welcome.blade.php</strong> and insert a hyperlink to the about page.</p>
<pre><code><span class="hljs-operator">&lt;</span>a href<span class="hljs-operator">=</span>”<span class="hljs-operator">/</span>about” title<span class="hljs-operator">=</span>”About”<span class="hljs-operator">&gt;</span>About<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>a<span class="hljs-operator">&gt;</span>
</code></pre><p>Reload the homepage and you should now see a link that goes to the About page. We have a problem though, we need to access the homepage in order to get to the new page we’ve created. This is not how navigations are meant to work! We could copy the link and insert it into the about.blade.php file, this isn't the way of doing it, but for now, you can add the hyperlink there to see how linking to each view works.</p>
<p>In the next article, I will show you the correct way of building up a navigation instead of repeating the HTML on every view we create. We will be using layouts.</p>
<p>If you’ve enjoyed this article, give it a clap and share it amongst family &amp; friends. You never know, it may help them in their journey in learning laravel. If you have any comments, feel free to use the comments box or tweet me at @mjcoder on twitter.</p>
<p>Thanks for reading.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Started — Installing Laravel 5.7 on Windows]]></title><description><![CDATA[Quick Update
So you may have been wondering where on earth have I gone and why there haven't been any updates of my Laravel journey, well I’ll keep this short and sweet, I broke my little finger & torn the ligament in it, so you can imagine I had one...]]></description><link>https://blog.mjcoder.co.uk/installing-laravel</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/installing-laravel</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[development]]></category><category><![CDATA[Windows]]></category><category><![CDATA[composer]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Wed, 12 Dec 2018 12:40:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800882962/3A-g5bqsI.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-quick-update">Quick Update</h3>
<p>So you may have been wondering where on earth have I gone and why there haven't been any updates of my <strong>Laravel</strong> journey, well I’ll keep this short and sweet, I broke my little finger &amp; torn the ligament in it, so you can imagine I had one floppy finger. I also became a proud father just over 3 months ago and life has just been a rollercoaster — now I have some time off work so I thought I’d best get back to this journey.</p>
<p>Image created on Canva</p>
<p>To begin installing Laravel on Windows you need to decide which of these tools you will be using on Windows OS to spin up a development environment. You have the choice of using the following but not restricted to;</p>
<ul>
<li><a target="_blank" href="https://www.apachefriends.org/index.html">XAAMP</a></li>
<li><a target="_blank" href="https://www.mamp.info/en/">MAMP</a></li>
<li><a target="_blank" href="http://www.ampps.com/">AMPPS</a></li>
</ul>
<p>I’ll be using XAAMP as I have this already installed on my computer. I won’t guide you on how to install XAAMP as there are loads of tutorials out there that will show you how to get that done.</p>
<p>Before installing Laravel, you need to install <a target="_blank" href="https://getcomposer.org">Composer</a>. You can either install it locally or globally. Locally means inside the project folder and globally means system-wide — so it’s accessible outside of the project folder.</p>
<blockquote>
<p>Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.</p>
</blockquote>
<p>As we are using a Windows OS we need to download composer using this <a target="_blank" href="https://getcomposer.org/Composer-Setup.exe">link</a>. This will ensure that Composer will install the latest version. We always want the most up to date version of Composer.</p>
<p>To quickly install Composer in the projects directory you need to run the following command in your terminal. You can use GitBash or the built-in terminal in Visual Code.</p>
<pre><code>php <span class="hljs-operator">-</span>r <span class="hljs-string">"copy('https://getcomposer.org/installer', 'composer-setup.php');"</span>  
php <span class="hljs-operator">-</span>r <span class="hljs-string">"if (hash\_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP\_EOL;"</span>  
php composer<span class="hljs-operator">-</span>setup.php  
php <span class="hljs-operator">-</span>r <span class="hljs-string">"unlink('composer-setup.php');"</span>
</code></pre><p>It’s really important that we install Composer globally, you only have to do this once, after all, we don’t want to be repeating ourselves for every new project we spin up. DRY!</p>
<p>You can find out how to do this by checking the official documentation on the Composer website <a target="_blank" href="https://getcomposer.org/doc/00-intro.md">here</a>.</p>
<iframe src="https://www.youtube.com/embed/ZocYVPP3nQY?feature=oembed" width="700" height="393"></iframe>

<h3 id="heading-installing-laravel-via-composer">Installing Laravel via Composer</h3>
<p>Fingers crossed that installing Composer has gone to plan if you’ve struggled, I’d recommend watching a few videos on YouTube on getting started with Composer.</p>
<p>Run this command in your terminal;</p>
<pre><code>composer <span class="hljs-keyword">global</span> <span class="hljs-keyword">require</span> laravel/installer
</code></pre><blockquote>
<p>Make sure to place composer’s system-wide vendor bin directory in your <code>$PATH</code> so the laravel executable can be located by your system. This directory exists in different locations based on your operating system; however, some common locations include:</p>
<p>macOS: <code>$HOME/.composer/vendor/bin</code></p>
<p>GNU / Linux Distributions: <code>$HOME/.config/composer/vendor/bin</code></p>
</blockquote>
<p>Once that has finished installing, the <em>laravel new</em> command will be available to use. The next command you need to run is;</p>
<pre><code>laravel <span class="hljs-keyword">new</span> <span class="hljs-operator">&lt;</span><span class="hljs-built_in">this</span> can be named anything<span class="hljs-operator">&gt;</span>
</code></pre><p>After the keyword, “new” give the laravel installation a suitable name. For example, if you are going to create a blog, then I’d call it a blog.</p>
<p>Here is a short video on how to install Laravel;</p>
<iframe src="https://www.youtube.com/embed/7YezCyBbqI0?feature=oembed" width="700" height="393"></iframe>

<h4 id="heading-local-development-server">Local Development Server</h4>
<p>If you have PHP installed locally and you would like to use PHP’s built-in development server to serve your application, you may use the <code>serve</code> Artisan command. This command will start a development server at <code>[http://localhost:8000](http://localhost:8000:)</code><a target="_blank" href="http://localhost:8000:">:</a></p>
<p>You should now be fully set up and be able to access the laravel installing on the localhost URL. I’ve kept this quite brief and not gone into greater detail on how to install Laravel &amp; Composer as there are loads of video guides out there available to you.</p>
<p>I hope you’ve enjoyed this post if you have, give it a clap and share. It’ll be highly appreciated. And if you want to join me on the Laravel journey, drop me a comment in the comments section &amp; I’ll get back to you. Thanks.</p>
]]></content:encoded></item><item><title><![CDATA[The road to becoming a Laravel PHP Artisan has begun!]]></title><description><![CDATA[Laravel Logo
So yeah, I’m starting to learn Laravel. If you Google Laravel, your almost certain to come across Laravel PHP Framework on the first page. It’s widely used amongst PHP developers. There are quite a few frameworks out there such as;

Cake...]]></description><link>https://blog.mjcoder.co.uk/the-road-to-becoming-a-laravel-php-artisan-has-started</link><guid isPermaLink="true">https://blog.mjcoder.co.uk/the-road-to-becoming-a-laravel-php-artisan-has-started</guid><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[frameworks]]></category><dc:creator><![CDATA[Mohammad Javed]]></dc:creator><pubDate>Sun, 19 Aug 2018 12:01:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800886434/F3OSk7nqrf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800886434/F3OSk7nqrf.png" alt /></p>
<p>Laravel Logo</p>
<p>So yeah, I’m starting to learn Laravel. If you Google Laravel, your almost certain to come across Laravel PHP Framework on the first page. It’s widely used amongst PHP developers. There are quite a few frameworks out there such as;</p>
<ul>
<li><a target="_blank" href="https://cakephp.org/">CakePHP</a></li>
<li><a target="_blank" href="https://www.codeigniter.com/">CodeIgniter</a></li>
<li><a target="_blank" href="https://symfony.com/">Symfony</a></li>
<li><a target="_blank" href="https://framework.zend.com/">Zend</a></li>
</ul>
<h3 id="heading-why-should-you-use-a-php-framework">Why should you use a PHP Framework?</h3>
<p>I’ll list a few good reasons why every developer should use a framework;</p>
<ul>
<li><strong>Less Code</strong> — We don’t want to lots of DRY code.</li>
<li><strong>Faster development</strong> — we all want to develop something quick &amp; not spend an eternity on doing the basics.</li>
<li><strong>Community Support</strong> — you’ll be able to collaborate with other developers, or if you have a problem, you’ll be able to post the problem on the support forum(s) and get help.</li>
<li><strong>Packages and Utilities</strong> — you’ll be able to integrate packages/utilities from fellow developers into the framework.</li>
<li><strong>Database Utilities/Migrations</strong> — migrate data from your code straight into the database.</li>
<li><strong>Authentication</strong> — save time writing your own code to process/validate authentications, most if not all frameworks should have this built in for you.</li>
</ul>
<h3 id="heading-why-do-you-want-to-learn-laravel">Why do you want to learn Laravel?</h3>
<p>The main reason why I want to learn Laravel is because it’s amazing framework packed with so many features that it makes life easier for the developer. I’ve seen first hand at what the developer can do with it and how quickly you can start putting stuff together from logins to dashboards.</p>
<p>A fellow Artisan developer, <a target="_blank" href="https://www.ivonunes.me/">Ivo Nunes</a> uses Laravel quite heavily and has built some amazing websites with the framework. i was intrigued at how quickly he would go from setting up the database, to the backend of Laravel and then build a front-end on top of the framework at such a ridiculous rate.</p>
<p>I wanted some of that quickness too! So here I am starting this exciting journey, the goal is more than just learning the framework, it’s to build something amazing with it. The possibilities with Laravel is endless. That is the greatest thing about it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650800887872/U47CYMGKY.jpeg" alt /></p>
<p>Photo by <a target="_blank" href="https://unsplash.com/@srz?utm_source=medium&amp;utm_medium=referral">sydney Rae</a> on <a target="_blank" href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></p>
<h3 id="heading-how-do-you-think-youll-get-on">How do you think you’ll get on?</h3>
<p>I feel confident, there are no nerves just pure excitement. I’ve already watched a few tutorial videos on YouTube by <a target="_blank" href="https://www.youtube.com/user/TechGuyWeb">Traversy Media</a> so it’s already given me a head start. Brad explains things quite clearly &amp; has loads of web development related videos that you can watch. i definitely will be diving in to those videos once I get to grips with Laravel.</p>
<p>There’s always support and very well written documentation at <a target="_blank" href="https://laravel.com/docs/5.6">Laravel</a> so I won’t be lost, there’s always going to be support, whether that’s through forums, social media, in-person, there’s always an Artisan on hand happy to help.</p>
<h3 id="heading-what-do-you-want-to-take-away-from-this-journey">What do you want to take away from this journey?</h3>
<p>Firstly, I don’t think this journey will end, it’s going continue regardless, this journey will just continue to grow and the learning growth will just be rising. What I’d like to take away from this journey is to have a PHP framework under my belt/skill set. It can do no harm.</p>
<p>With starting this journey it’ll grow me as a web developer which will ultimately end in me building more than just websites. As a developer you can’t stick to what you already know, you should always be challenging yourself to become a better web developer. My aim is to become a full-stack developer. It won’t be easy but let’s get the journey started.</p>
]]></content:encoded></item></channel></rss>