<?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: Ahmed sliman</title>
    <description>The latest articles on Forem by Ahmed sliman (@ahmedsliman).</description>
    <link>https://forem.com/ahmedsliman</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%2F29872%2Fa7b908e8-241f-4d2d-ac12-46cc9093c794.jpeg</url>
      <title>Forem: Ahmed sliman</title>
      <link>https://forem.com/ahmedsliman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ahmedsliman"/>
    <language>en</language>
    <item>
      <title>Laravel Events 101</title>
      <dc:creator>Ahmed sliman</dc:creator>
      <pubDate>Tue, 19 Dec 2023 09:08:04 +0000</pubDate>
      <link>https://forem.com/ahmedsliman/laravel-events-for-newbies-1kpo</link>
      <guid>https://forem.com/ahmedsliman/laravel-events-for-newbies-1kpo</guid>
      <description>&lt;h2&gt;
  
  
  What is Event-Driven Programming?
&lt;/h2&gt;

&lt;p&gt;Simply put, events are actions that occur within an application. Coming from the world of JavaScript, you probably understand events as user actions such as mouse click, mouseover, key press, etc. In Laravel, events can be various actions that occur within an application such as email notifications, logging, user sign-up, CRUD operations, etc. Laravel events provide a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why should we use Events?!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Easier to maintain (SOLID).&lt;/li&gt;
&lt;li&gt;Less risk of regression,&lt;/li&gt;
&lt;li&gt;Make classes responsible for only one thing,&lt;/li&gt;
&lt;li&gt;Make team’s work easier,&lt;/li&gt;
&lt;li&gt;Expect the unexpected, If you ever need to add new functionality, all you need to do is create a new listener and register it with the event. Job is done!&lt;/li&gt;
&lt;li&gt;Your logic is separated and now the Controller has much-reduced responsibility&lt;/li&gt;
&lt;li&gt;Allow asynchronous tasks easily (queues in Laravel).&lt;/li&gt;
&lt;li&gt;Be ready for broadcasting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's compare two pieces of code with/without events
&lt;/h2&gt;

&lt;h3&gt;
  
  
  With
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy7e2o0uesnkyxn8q7l4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy7e2o0uesnkyxn8q7l4v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Without
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqdpjjp8cdroftvyn4yed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqdpjjp8cdroftvyn4yed.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How do we create Events?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Defining Our Events
&lt;/h3&gt;



&lt;p&gt;&lt;code&gt;php artisan make:event UserRegistered&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The event has been created successfully&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:listener SendWelcomeMail --event=UserRegistered&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The listener has been created successfully&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:listener SignupForWeeklyNewsletter --event=UserRegistered&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The listener has been created successfully&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:listener SendSMS --event=UserRegistered&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The listener has been created successfully&lt;/p&gt;

&lt;h2&gt;
  
  
  ESP - EventServiceProvider
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0svwe6ivibsptoew00nw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0svwe6ivibsptoew00nw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan event:generate&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Events and Listeners generated successfully&lt;/p&gt;

&lt;h2&gt;
  
  
  Stopping The Propagation Of An Event
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi1pjxkfyjxmvy95ct6f2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi1pjxkfyjxmvy95ct6f2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Eloquent Native Events
&lt;/h2&gt;

&lt;p&gt;With his Eloquent model, Laravel will automatically fire &lt;strong&gt;created&lt;/strong&gt;, &lt;strong&gt;saved&lt;/strong&gt;, &lt;strong&gt;updated&lt;/strong&gt; and &lt;strong&gt;deleted&lt;/strong&gt; events respectively.&lt;/p&gt;

&lt;p&gt;To start listening to model events, define a &lt;strong&gt;$dispatchesEvents&lt;/strong&gt; property on your Eloquent model. This property maps various points of the Eloquent &lt;strong&gt;model's&lt;/strong&gt; lifecycle to your event classes. Each model event class should expect to receive an instance of the affected model via its constructor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eloquent Native Events
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz8l2njjzzyioogdrctx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz8l2njjzzyioogdrctx5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3d7qwjxzpk4jm87ya0n0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3d7qwjxzpk4jm87ya0n0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>events</category>
    </item>
    <item>
      <title>Why MobX?</title>
      <dc:creator>Ahmed sliman</dc:creator>
      <pubDate>Wed, 07 Sep 2022 09:27:34 +0000</pubDate>
      <link>https://forem.com/ahmedsliman/why-mobx-40o8</link>
      <guid>https://forem.com/ahmedsliman/why-mobx-40o8</guid>
      <description>&lt;p&gt;&lt;strong&gt;MobX?&lt;/strong&gt;&lt;br&gt;
It's an open source state management tool. When creating a web application, developers often seek an effective way of managing state within their applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why MobX?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MobX get you an ability to handle multiple data-structures of states&lt;/li&gt;
&lt;li&gt;Sync render by tracking  observable pieces of state&lt;/li&gt;
&lt;li&gt;Help on scalable applications with manage state easily&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is State?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Application state refers to the entire model of an application and can contain different data types including arrays, numbers, and objects. In MobX, actions are methods that manipulate and update the state. These methods can be &lt;a href="https://blog.logrocket.com/how-to-dynamically-create-javascript-elements-with-event-handlers/"&gt;bound to a JavaScript event handler&lt;/a&gt; to ensure a UI event triggers them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MobX concepts&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MobX has four principle concepts that we should learn, to understand how it works: &lt;strong&gt;observables&lt;/strong&gt;, &lt;strong&gt;computed values&lt;/strong&gt;, &lt;strong&gt;reactions&lt;/strong&gt; and &lt;strong&gt;actions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;MobX also introduces a few concepts: state, actions, and derivations (including reactions and computed values).&lt;/li&gt;
&lt;li&gt;By wrapping the component with an observer, it will now automatically become aware of changes in the store&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>The Clean Architecture In PHP</title>
      <dc:creator>Ahmed sliman</dc:creator>
      <pubDate>Tue, 15 Mar 2022 16:57:31 +0000</pubDate>
      <link>https://forem.com/ahmedsliman/the-clean-architecture-in-php-1mno</link>
      <guid>https://forem.com/ahmedsliman/the-clean-architecture-in-php-1mno</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_h_j2slJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi6m0hlfm0kqb0lfj84h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_h_j2slJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi6m0hlfm0kqb0lfj84h.png" alt="Image description" width="301" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This book is amazing in explaining and applying SOLID principles and many common design patterns.&lt;/li&gt;
&lt;li&gt;The main benefit of the book is it give a quick theoretical introduction then start applying in a really advanced way the clean (onion) architecture.&lt;/li&gt;
&lt;li&gt;Some parts was very brief, So I got help from other resources.&lt;/li&gt;
&lt;li&gt;Other benefit of the book is applying the principles in a small project that getting bigger throughout the book, and it also apply how to trasfer the project from a framework to another to expose the concepts of decoupling. So, you will find it go from Zend, Laravel to Symfony.&lt;/li&gt;
&lt;li&gt;It's a short review as it's more like my impression for a good journey :)&lt;/li&gt;
&lt;/ul&gt;

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