ホーム > Laravel > When to Use Laravel's make:command?
Laravel

When to Use Laravel's make:command?

Thank you for your continued support.
This article contains advertisements that help fund our operations.

⇨ Click here for the table of contents for Laravel articles

In Laravel, you can create custom php artisan commands.

The method of creating them is explained in this article.

⇨How to Use Arguments in Laravel Commands

Let's explore what you can achieve by using these commands.

Environment

Laravel Framework 8.60.0

Sending Mass Emails at a Specific Time

By using commands with a scheduler, you can send mass emails at a specific time

The method of setting up a schedule is explained in the article below.

Let's break down the tasks.

  1. Create a Mail function to send emails to users
  2. Create a command to trigger the Mail function for all users
  3. Set up the scheduler

By following the above steps, you can send mass emails at a specific time.

(Note: The number of emails that can be sent in bulk may vary depending on the email service. Understand the specifications well before implementation)

Performing Periodic Calculations

This is referred to as batch processing.

What is Batch Processing?

Batch processing refers to performing processes in bulk.

For example, in a service with a large number of users like YouTube, if you want to display the "number of likes" on the video list page, calculating it for each individual video would take a lot of time.

Therefore, by pre-calculating the "number of likes" associated with each video and saving the results in the database, you can perform the calculations in advance, making it easier to handle subsequent calculations when users visit.

The use of batch processing in the example mentioned above is effective for improving performance when a user's page loading time is high.

It's important to note that batch processing is not suitable for situations where data updates need to be immediate.

Making Changes to the Database Using Laravel's Eloquent Instead of SQL

There are many cases where changes need to be made to the database to meet specifications.

In such cases, if SQL statements seem daunting, difficult, or incomprehensible, using Laravel's code might make implementation easier.

In such situations, you can prepare processing functions in advance with a command, and then execute the command after making changes to the database to match them.

This approach can also be used when rewriting master tables, and it provides a sense of security when making changes based on the environment and circumstances.

Database changes should always be approached with caution, and you'll want to make choices with minimal risk.

Summary

That's all for now.

I summarized the usage of commands somewhat.

I think the basic concept is to use them in conjunction with a scheduler.

For feedback or complaints, please contact me via Twitter DM.

That's all!

Popular Articles

Deploying PHP7.4 + Laravel6 Project to AWS EC2

Implementing Breadcrumbs in Laravel with laravel-breadcrumbs

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!