<?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: Amir Haghi</title>
    <description>The latest articles on Forem by Amir Haghi (@hamidatjajiga).</description>
    <link>https://forem.com/hamidatjajiga</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%2F939715%2F9f2a8fe7-717e-4226-b749-e1a90e5aff7b.png</url>
      <title>Forem: Amir Haghi</title>
      <link>https://forem.com/hamidatjajiga</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hamidatjajiga"/>
    <language>en</language>
    <item>
      <title>How to test task scheduling in Laravel</title>
      <dc:creator>Amir Haghi</dc:creator>
      <pubDate>Sat, 01 Apr 2023 08:43:16 +0000</pubDate>
      <link>https://forem.com/hamidatjajiga/testing-task-scheduling-in-laravel-45g</link>
      <guid>https://forem.com/hamidatjajiga/testing-task-scheduling-in-laravel-45g</guid>
      <description>&lt;p&gt;I want to say my own experience about how to test task scheduling in Laravel. There is a task scheduler in Laravel that you can write your task in a callback function and it is completely explained in the &lt;a href="https://laravel.com/docs/10.x/scheduling"&gt;docs&lt;/a&gt;. When it comes to testing it is possible to work with some sort of &lt;a href="https://laravel.com/docs/9.x/mocking#interacting-with-time"&gt;time traveling&lt;/a&gt; but I'm not sure about that.&lt;/p&gt;

&lt;p&gt;The way that I do is that I write my task in a &lt;a href="https://laravel.com/docs/10.x/artisan"&gt;command&lt;/a&gt; and as we know a command is a regular class of PHP and we can write tests for that to be sure that is working correctly. But for task scheduling, in order to be sure that the task will be run on the specific time intervals, we have to trust to the core task schedulers of servers maybe :)&lt;/p&gt;

&lt;p&gt;So test your own task correct and test it and trust to on to run your task is every interval. &lt;/p&gt;

&lt;p&gt;Tell your opinion please.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tdd</category>
      <category>php</category>
    </item>
    <item>
      <title>Run Laravel test multiple times</title>
      <dc:creator>Amir Haghi</dc:creator>
      <pubDate>Thu, 30 Mar 2023 07:18:46 +0000</pubDate>
      <link>https://forem.com/hamidatjajiga/run-laravel-test-multiple-times-5c8h</link>
      <guid>https://forem.com/hamidatjajiga/run-laravel-test-multiple-times-5c8h</guid>
      <description>&lt;p&gt;If your test fails in some rare cases and you want to see when it fails, you can write a bash script like this for run it over and over.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in {1..100}; 
do 
    php artisan test --filter test_something; 
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It would be better to have this feature built in Laravel but currently I haven't seen it in the docs.&lt;/p&gt;

&lt;p&gt;I know it was simple but when we do not code in bash every day, we cant remember its syntax. so consider this like a note to check it when it was required.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>phpunit</category>
      <category>tdd</category>
    </item>
    <item>
      <title>Make a simple nav-bar with Laravel and Bootstrap</title>
      <dc:creator>Amir Haghi</dc:creator>
      <pubDate>Sun, 11 Dec 2022 07:08:31 +0000</pubDate>
      <link>https://forem.com/hamidatjajiga/make-a-simple-nav-bar-with-laravel-and-bootstrap-433j</link>
      <guid>https://forem.com/hamidatjajiga/make-a-simple-nav-bar-with-laravel-and-bootstrap-433j</guid>
      <description>&lt;p&gt;Bootstrap has it's own component to make navbar and you can see that &lt;a href="https://getbootstrap.com/docs/5.2/components/navbar/"&gt;here&lt;/a&gt;. In this tutorial we want to show how to use it in Laravel. &lt;br&gt;
First of all you have to include bootstrap's CSS file in your project. if you want to use JS features it is required to use JS file also. &lt;br&gt;
lets create some routes in laravel:&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('/', 'home')-&amp;gt;name('home');
Route::view('/about', 'about')-&amp;gt;name('about);
Route::view('/contact', 'contact')-&amp;gt;name('contact');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In views you can &lt;code&gt;@include()&lt;/code&gt; nav-bar view like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@include('nav-bar') 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now lets create the &lt;code&gt;nav-bar.blade.php&lt;/code&gt; for navbar you can use the default &lt;a href="https://getbootstrap.com/docs/5.2/components/navbar/"&gt;nav bar of bootstrap&lt;/a&gt;. &lt;br&gt;
and generate links like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;li class="nav-item"&amp;gt;
    &amp;lt;a class="nav-link @if(Route::currentRouteName() == 'home') active @endif" href="{{ route('home') }}"&amp;gt;Home&amp;lt;/a&amp;gt;
&amp;lt;/li&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;As you can see for making active routes bold you have to write a complicated code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@if(Route::currentRouteName() == 'home') active @endif 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Easier way to activate links in Laravel
&lt;/h2&gt;

&lt;p&gt;For making links active you can use the &lt;a href="https://github.com/tuytoosh/active"&gt;Active package&lt;/a&gt; and it really makes your code easy and instead of using above code you can write this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@active('home') 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the package &lt;a href="https://github.com/tuytoosh/active"&gt;here&lt;/a&gt;. I hope it helps you.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>bootstrap</category>
    </item>
  </channel>
</rss>
