<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tim E</title>
    <description>The latest articles on DEV Community by Tim E (@tim-e).</description>
    <link>https://dev.to/tim-e</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%2F1500940%2Ff164c91b-df34-49ff-93f3-bdf139091867.jpg</url>
      <title>DEV Community: Tim E</title>
      <link>https://dev.to/tim-e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tim-e"/>
    <language>en</language>
    <item>
      <title>Using observers in Laravel to track model events</title>
      <dc:creator>Tim E</dc:creator>
      <pubDate>Fri, 04 Oct 2024 04:53:42 +0000</pubDate>
      <link>https://dev.to/tim-e/using-observers-in-laravel-to-track-model-events-3bii</link>
      <guid>https://dev.to/tim-e/using-observers-in-laravel-to-track-model-events-3bii</guid>
      <description>&lt;p&gt;In modern applications, reacting to changes in your data in real-time is essential, whether it's logging changes, sending notifications, or tracking user behavior. Laravel makes this easier with Observers, which allow you to hook into model events and run code when specific actions occur—such as creating, updating, or deleting a model.&lt;/p&gt;

&lt;p&gt;In this tutorial, I'll walk you through setting up Observers in Laravel and show how you can use them for tasks like tracking and logging data changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Are Laravel Observers?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Laravel Observers are classes that group event-listening methods for a model. These allow you to "observe" a model and react when something happens to it, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created&lt;/li&gt;
&lt;li&gt;Updated&lt;/li&gt;
&lt;li&gt;Deleted&lt;/li&gt;
&lt;li&gt;Restored&lt;/li&gt;
&lt;li&gt;Force Deleted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using observers, you can separate the logic for handling model events from the models themselves, making your code cleaner and easier to maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Creating an Observer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s start by creating a basic Observer. In this example, we'll track changes to a Post model when it's created and updated.&lt;/p&gt;

&lt;p&gt;To generate an observer class, run the following Artisan command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:observer PostObserver --model=Post```



This will create a PostObserver class in the app/Observers directory and automatically link it to the Post model.

**Step 2: Defining Observer Methods**
Next, open the newly created PostObserver.php file. You’ll see some predefined methods, such as created and updated. Here’s how you can fill them in to log messages whenever a post is created or updated:



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

&lt;/div&gt;

&lt;p&gt;&amp;lt;?php&lt;/p&gt;

&lt;p&gt;namespace App\Observers;&lt;/p&gt;

&lt;p&gt;use App\Models\Post;&lt;/p&gt;

&lt;p&gt;class PostObserver&lt;br&gt;
{&lt;br&gt;
    /**&lt;br&gt;
     * Handle the Post "created" event.&lt;br&gt;
     *&lt;br&gt;
     * &lt;a class="mentioned-user" href="https://dev.to/param"&gt;@param&lt;/a&gt;  \App\Models\Post  $post&lt;br&gt;
     * @return void&lt;br&gt;
     */&lt;br&gt;
    public function created(Post $post)&lt;br&gt;
    {&lt;br&gt;
        \Log::info("Post created: {$post-&amp;gt;id}");&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Handle the Post "updated" event.
 *
 * @param  \App\Models\Post  $post
 * @return void
 */
public function updated(Post $post)
{
    \Log::info("Post updated: {$post-&amp;gt;id}");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Here, we are simply logging the event for demonstration purposes. In a real-world application, you might want to trigger actions like sending an email or updating an analytics platform like EventScout.io.

**Step 3: Registering the Observer**
To have the observer listen for events, you need to register it in the AppServiceProvider.php file. Add this inside the boot method:



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

&lt;/div&gt;

&lt;p&gt;use App\Models\Post;&lt;br&gt;
use App\Observers\PostObserver;&lt;/p&gt;

&lt;p&gt;public function boot()&lt;br&gt;
{&lt;br&gt;
    Post::observe(PostObserver::class);&lt;br&gt;
}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Now, every time a post is created or updated, Laravel will call the corresponding method in the PostObserver and execute the logic you defined.

**Step 4: Testing the Observer**

Now that the observer is set up, you can test it by creating or updating a Post model. For example:



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

&lt;/div&gt;

&lt;p&gt;$post = Post::create(['title' =&amp;gt; 'First Post', 'body' =&amp;gt; 'This is the body of the post.']);&lt;/p&gt;

&lt;p&gt;// Update the post&lt;br&gt;
$post-&amp;gt;update(['title' =&amp;gt; 'Updated Post']);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Check your logs, and you should see entries like:



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

&lt;/div&gt;

&lt;p&gt;[2024-10-04 12:34:56] local.INFO: Post created: 1&lt;br&gt;
[2024-10-04 12:36:12] local.INFO: Post updated: 1&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


**Why Observers are Perfect for Event-Driven Tracking**

Observers allow you to track key events in your application seamlessly. You can build logging mechanisms, audit trails, or even integrations with external services. If you're looking for more robust event tracking—beyond just model events—consider checking out [EventScout.io](https://eventscout.io), a simple yet powerful analytics and automation platform designed for startups and developers.

With EventScout, you can track user behavior, product usage, and monitor events across your applications in real-time—all without building your own analytics infrastructure from scratch. Whether you're logging basic events in Laravel or need detailed analytics, EventScout has you covered.

**Conclusion**

Laravel Observers are an elegant way to handle model events, making your code more organized and your application more responsive to changes. They are an excellent tool for developers who want to implement event-driven architectures or logging systems.

If you're interested in taking this to the next level with product analytics and automation, don't forget to explore [EventScout.io](https://eventscout.io).

Happy coding!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>laravel</category>
      <category>eventdriven</category>
      <category>architecture</category>
      <category>php</category>
    </item>
    <item>
      <title>How to get hired: Insights from an Engineering Manager</title>
      <dc:creator>Tim E</dc:creator>
      <pubDate>Thu, 16 May 2024 10:36:33 +0000</pubDate>
      <link>https://dev.to/tim-e/how-to-get-hired-insights-from-an-engineering-manager-48pa</link>
      <guid>https://dev.to/tim-e/how-to-get-hired-insights-from-an-engineering-manager-48pa</guid>
      <description>&lt;p&gt;I'm an Engineering manager, and I DID use ChatGPT to help me write this article 😅. Let's just be honest and get that out of the way up front.&lt;/p&gt;

&lt;p&gt;In this article I'll talk about what you can do to stand out as a candidate when looking for job as a software engineer. I'll tell you some of the things I look out for that might just help you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where we're at&lt;/strong&gt; 🗺️&lt;br&gt;
The job market is quite unique at the moment. The last few years have seen a lot of uncertainty. Economic downturn, mass layoffs, high inflation, uncertainty over the impact of AI. Compared to the last decade or so, the job market today can be quite challenging. There are a lot of great engineers available and still a lot of uncertainty. The supply and demand equation is tilted in the wrong direction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It starts with your presence&lt;/strong&gt; 🏁&lt;br&gt;
Whether its a resume, or a LinkedIn profile, a potential employers first impression of you will come from one of these places, so make sure you've spent the time to prepare.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cover letters&lt;/strong&gt; 📨&lt;br&gt;
Honestly, I barely ever read cover letters. They're always very generic, and don't usually offer me much insight into the candidate. Unless you make yours short, snappy and unique, I'll probably eyeball it and move on quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The resumé&lt;/strong&gt; 🗂️&lt;br&gt;
In many ways cover letters and resumés feel antiquated. Do managers actually read them? I do read them, but I prefer resumés that are short, sharp and to the point. I want to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When and where you worked&lt;/li&gt;
&lt;li&gt;What you did&lt;/li&gt;
&lt;li&gt;Why it matters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I usually look for when scanning resumés is the name or types of company the person has worked for. If you've worked at FAANG, I'll pay attention. If you've worked companies that are known to have excellence in software engineering, I'll pay attention. If you've only worked at agencies, that will stand out to me (because I hire for product engineering teams).&lt;/p&gt;

&lt;p&gt;The more specific you can be about what you did in your role at the company, the more I'll consider it. Just mentioning broad keywords is a lot less effective than telling me about a specific project you worked on. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your LinkedIn profile&lt;/strong&gt; 🔗&lt;br&gt;
There are some basics in your LinkedIn profile that nearly seem like common sense but you would be surprised how often are missed.&lt;/p&gt;

&lt;p&gt;Make sure you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a decent profile photo - I'd like to see who I'm going to meet&lt;/li&gt;
&lt;li&gt;Your work history with at minimum the same detail as a resume - Where, when, why&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To add some credibility to your profile:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recommendations from past colleagues&lt;/li&gt;
&lt;li&gt;Posts around relevant topics&lt;/li&gt;
&lt;li&gt;Connections or following of industry or domain experts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A GitHub profile&lt;/strong&gt; ⚙️&lt;br&gt;
If you're trying to land a job as a software engineer, I'd expect to see some kind of public GitHub profile. It doesn't necessarily mean you have to have released your own OSS library, but anything you can show in your profile lends to your credibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The interview&lt;/strong&gt; 👩‍💻&lt;br&gt;
The most critical component (to me anyway) of any candidate is their ability to communicate. For software engineers, the ability to communicate complex concepts and ideas is as important as breathing. If you can't communicate well, it doesn't matter how good of an engineer you are.&lt;/p&gt;

&lt;p&gt;Depending on the interview stage and format, I'll also be watching how you approach problems or situations you might be presented with. The first sign for me of a good engineer, is someone that asks a lot of questions. In some interviews I will present a hypothetical scenario and ask the candidate to assist in designing a solution. If the candidate doesn't start with asking clarifying questions then they're off to a bad start. Following this I'll be looking for fundamentals - software design patterns, system design principles, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary of what I look for&lt;/strong&gt; 🔎&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strong communication, particularly of technical concepts&lt;/li&gt;
&lt;li&gt;Structured and fastidious problem solving&lt;/li&gt;
&lt;li&gt;Technical skills and experience&lt;/li&gt;
&lt;li&gt;Credibility - Working at well-known companies, OSS contributions, articles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As both an engineer, and a manager, I've been on both ends of the process and have had equal frustration on both sides. This is partly what has driven me to develop a new platform for connecting developers with employers and recruiters - DevBuilt - &lt;a href="https://devbuilt.io/"&gt;https://devbuilt.io/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
