Durbin – monitor Docker Containers remotely

You’ve installed Docker on your server and running some apps in containers. Awesome! 🙌 🎉
But wait..

  • How do you check which containers are running and which are stopped at this moment?
  • How do you check their logs when needed?
  • Can you stop/start them without logging into the remote server?

This is where you’ll require Durbin! It’s a lightweight PHP script, designed to provide a simple monitoring solution for Docker Containers running on a remote server.

Continue reading →

Laravel Gates – a graphical intro for beginners

Gates! The first impression it makes is “way to enter somewhere”. But, in reality, the primary responsibility of a gate is to prevent unwanted entry. Another perspective of thinking about gates is – different gates will take you to different places.

Laravel picked this word, “Gate” to name its basic authorization system. What a beautiful similarity between the purpose of an authorization system and the real life gates!

In this post, we are going to:

  • Take a simple application as an example scenario.
  • Identify the usages of authorization in this application.
  • And then, how we can solve it using Laravel Gates.
Continue reading →

Implementing Maker-Checker Workflow in Laravel Filament v3

Maker-Checker Approval Workflow

Maker-Checker (also known as the four-eyes principle) is a widely used workflow for approving sensitive and impactful actions. It’s a control mechanism that requires two different individuals to complete a task. In simple terms, Maker-Checker Workflow is a process where an individual creates or produces content (maker), then another personnel (checker) reviews and verifies its accuracy before publishing or approving it. This process ensures that the content meets quality standards and is reliable.

Let’s take a simple scenario to make a Maker-Checker approval workflow in Laravel. Also, we’ll use Filament V3 for building the CRUD features for the entity with minimal effort. Once you get the core concept, you can build it inside any application – Filament is not essential.

Once you get the core concept, you can build it inside any application – Filament is not essential.

Example Scenario

In this tutorial, we’ll build a News Article publishing system with a maker-checker workflow using Laravel Filament v3. We’ll start with a basic News model and gradually add workflow functionality.

Think of it like a two-step review process, similar to how editors check written work for grammar and spelling errors before publication. We have two roles involved in this process – “reporter” and “editor“. Here is the workflow we want to build:

  • Reporter creates new News article. It’s in draft state initially.
  • Reporter can submit it (submitted) for review or cancel it (cancelled).
  • Editor will now review the article.
  • Then, he’ll either approve it (approved) or reject it (rejected).
  • Editor may also cancel the article (cancelled)
  • If rejected, Reporter can update it and submit again (submitted)
  • Editor can publish (published) the approved news articles at appropriate time.
State Diagram: Maker-Checker workflow
Continue reading →

Let’s beautify Filament 3 login page

Laravel Filament 3 provides unparalleled productivity with pretty good design for building admin panels and back-office applications. It’s a robust admin builder based on TALL stack. However, the default login page it shows is… not so interesting.

So, I’ve tried to customize the filament v3 login page by adding some styles and contents to the login page. After exploring some options, I’ve figured out the simplest way of to customizing the login page design with minimum effort.

Image: Customized login page of Laravel Filament v3

Let’s change the login page design like the above screenshot. Hang tight, it’s just in a few steps, will not take more then 5 minutes.

Continue reading →

Using MySQL’s Event Scheduler (No cron job)!

In MySQL, you can use the Event Scheduler to periodically refresh or update table data at specified intervals.

Here’s a step-by-step guide on how to set up a scheduled event to refresh table data every 1 hour:

1. Enable Event Scheduler:

Before you can use the Event Scheduler, make sure it is enabled. You can enable it by setting the event_scheduler system variable.

-- Enable the Event Scheduler
SET GLOBAL event_scheduler = ON;

2. Create a Stored Procedure:

Create a stored procedure that contains the logic to refresh or update the table data. Replace your_table and your_refresh_logic with your actual table name and refresh logic.

DELIMITER //

CREATE PROCEDURE RefreshTableData()
BEGIN
    -- Your refresh logic here (e.g., replace this comment with actual SQL statements)
    -- UPDATE your_table SET column1 = value1, column2 = value2, ...;

    -- Commit changes if needed
    -- COMMIT;
END //

DELIMITER ;

3. Create a Scheduled Event:

Create a scheduled event that calls the stored procedure at the desired interval (every 1 hour in this case).

-- Create a scheduled event
CREATE EVENT IF NOT EXISTS hourly_refresh
ON SCHEDULE EVERY 1 HOUR
DO
    CALL RefreshTableData();

4. Verify the Event:

You can check if the event is created and enabled by querying the events table.

-- Check events
SHOW EVENTS;

Important Notes:

  • Ensure that the event_scheduler variable is set to ON at the session or global level.
  • Adjust the stored procedure (RefreshTableData()) with the actual SQL statements to refresh your table data.
  • Make sure to test the stored procedure independently before creating the scheduled event.
  • The example assumes that your MySQL user has the necessary privileges to create events.

By following these steps, you can set up a scheduled event in MySQL to refresh a table data every 1 hour. Adjust the table name and refresh logic according to your specific use case.

Laravel Livewire V3 – Getting Started (1/3)

Livewire is a Laravel package to make powerful, dynamic, front-end UI. It offers a convenient way of building SPA-like interactive apps with PHP (without writing JavaScript).

On July 20th of 2023, at Laracon US, the new shiny Laravel Livewire v3 is officially released. With the new Alpine based core and a bunch of new features – it’s going to be awesome!

Let’s explore the fresh, out-of-the-oven Livewire. ♨️

We are going to build a Fortune Cookie Message app. These are small, inspirational, positive messages printed on paper and served inside specially shaped cookies. See the story here.

FortuneCookieMessage app with Laravel Livewire V3

We’ll make it in a 3 step journey with the following milestones:

  1. Make a new Livewire app. Show up a different inspirational message every time we hit a button.
  2. Add an Emoji reaction counter. Explore various livewire features.
  3. Make an admin section with authentication and a data grid.

It’s small enough to try and complete within a day but has the scope of exploring various interactivity features.

Continue reading →

How to get all indexes of a table in Laravel

You can list all indexes of a table, along with the field names in Laravel. It’s very quick and easy with DB Facade and Laravel Collection.

Here is the code you’ll need. Right, just a single, chained statement! 😉

use Illuminate\Support\Facades\DB;

collect(DB::select("SHOW INDEXES FROM products"))
    ->mapToGroups(fn($row) => [$row->Key_name => $row->Column_name])
    ->toArray();

The output will be something like the following.

Continue reading →

New Laravel app with a head start from CLI

Sometimes, we want to quickly try out a new product idea. But where to start? 🤔

Just open your terminal, copy-paste the following commands, and you’ll get a basic Laravel app in 5 minutes. Additionally, it’ll have some basic things ready like login, registration, user profile, user listing, etc. Ready to build anything upon this base.

Now, it’s your time to focus on your very own idea. 🚀

Continue reading →