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 →

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 →

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 →

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.

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 →

E-Code Verifier relocated

E-Code Verifier is a free web application for checking/verifying Shariah status (Halal, Haram, Mushbooh) of E Code (food ingredient codes). It was developed as a PWA and published in Jun 2016 at ecode.halal-haram.com. By the time of July 2018, it was hitting 12k+ traffic monthly from search engines (without any kind of promotion) and also a good number of usages from desktop/mobile installations.

E-Code Verifier Analytics of 2018
E-Code Verifier Analytics of mid-2018

A few months ago, the domain “halal-haram.com” got expired! And I have been very busy at that time and didn’t notice! When I realized it, it’s already too late to recover. So, I have relocated it to ecode.figlab.io.

I hope it will become useful again and will save thousands of Muslims from consuming foods with haram ingredients unintentionally.

A free, hosted, advanced wiki – Dropbox Paper

Around a year ago, while starting a new project, I was asking a friend and colleague for a suggestion between Docuwiki and Confluence to use as team wiki. He suggested trying Dropbox Paper instead. I’ve tried, and the result was amazing!

Since then, using it as the team wiki for several projects happily. In this post, I’ll share some of the points which convinced me to use Dropbox Paper as a wiki (or alternative of wiki) for a team.

Why Dropbox Paper?

Take 3 minutes to go through the following points and screenshots. Hopefully, you’ll find Dropbox Paper a good fit for many of your situations where you’ll use a wiki.

Continue reading →