アプリ関連ニュース

Laravel 8 Push Notification using Firebase[1]

Firstly create a new fresh Laravel project using a composer command:

composer create-project laravel/laravel push-notification-app

Then go to the app’s root:

cd push-notification-app/

Database Connection

Secondly, to make a database connection in .env file filling with database name, username, password.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=database_user_name
DB_PASSWORD=database_password

Install Laravel UI Scaffolding

Next, install ui package and create auth scaffolding based on Bootstrap CSS framework.

composer require laravel/ui

After that, need to install to manifest bootstrap auth ui.

php artisan ui bootstrap --auth

You have to suggested commands to compile your fresh scaffolding.

npm install && npm run dev

Update Server Key in User Table

We need to add a new column in the current user table.

php artisan make:migration add_column_device_token

Subsequently, we need to add this device token key in the new table.

class AddColumnDeviceToken extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::table('users', function (Blueprint $table) {
            $table->string('device_token')->nullable();
        });
    }

After that, move the device key to the user table.

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'device_token'
    ];

Then type to run migrate execute command.

php artisan migrate

Next week I will show you how to get the Firebase cloud messaging server key and Firebase web app’s configuration credentials.

By Ami



Switchでゲームプログラミング

Nintendo Switch用ソフトの
ナビつき!つくってわかる はじめてゲームプログラミング
を購入してすこし遊んでみました。

続きを読む

Adding Recaptcha verification to your form

We all create forms in your system & applications. If you are a web developer , you may experience once or more creating forms. For example contact form , registration form etc. Recaptcha is a free service supported by Google which helps to protect our websites from spam and abuse. Basically A “CAPTCHA” is a test to separate human and bots apart.

Today I will guide you how to add a reCAPTCHA service in your form easily.

First thing first, we need to generate a reCAPTCHA key to add in our form. You can go to this link and click + button to create a key.

This will proceed to a form to choose the options like this.

There are two versions of reCAPTCHA type for now , version 2 and 3. With reCAPTCHA v2, the only action required was to check if the user successfully solved the challenge or not. With reCAPTCHA v3, you must now decide what action to take based on the score. you may choose depending on your favour. In this tutorial , I will use v2 as I like its simplicity.

After filling up the form, you will get the reCAPTCHA site key like this.


For the source code part, we need to import the reCaptcha API JS in a script tag like this.

<script src=https://www.google.com/recaptcha/api.js></script>

And we can embed our site key in HTML.

<div class="g-recaptcha" data-sitekey="YOUR-SITE-KEY-HERE"></div>

Of course you can modify the css class as you like. For the validation, we can use grecaptcha.getResponse()function to validate the reCAPTCHA response. I will add a example code which is used in my project.

//This is just a sample code and can differ depending on your //source code.
if ($('.g-recaptcha').length > 0) {
   if (grecaptcha.getResponse() == "") {
      flag = 1;
        alert('Please verify Recaptch');
   } else {
      flag = 0;
   }
}

// You can also read the official documentation.
// https://developers.google.com/recaptcha/intro

As a final result on the browser, you will get a reCAPTCHA checkbox like this. This may also differ depending on your design preferences.

By Yuuma



Tips for Excel calculation

Today I would like to share some important tips about excel calculation. Sometimes, we change today date but it change automatically arriving today date when we open the file.

In this time, how to fix it.

How to Change Excel Calculation Options

Select the data we want to change and go the Excel ribbon > Formulas tab > Calculation group, click the Calculation Options button and select one of the following options:

Automatic (default) – tells Excel to automatically recalculate all dependent formulas every time any value, formula, or name referenced in those formulas is changed.

Manual – turns off automatic calculation in Excel. Open workbooks will be recalculated only when you explicitly do.

How to force recalculation in Excel

To manually recalculate all open worksheets and update all open chart sheets, go to the Formulas tab > Calculation group, and click the Calculate Now button.

Hope you find it interesting and useful.

By Ami



[Laravel] Adding custom data to eloquent result

Sometimes, we want to add more custom data to our eloquent result before passing to blade or doing further logic improvements. Today we will be focusing how to add custom data to our eloquent result.

I assume you already know laravel framework in this article as we will not covering from scratch of laravel framework. First let’s make a posts table. Here is the migration file.

Schema::create('posts', function (Blueprint $table) {
  $table->id();
  $table->string('name');
  $table->string('description');
  $table->timestamps();
});

In our post table, we will have these columns in above. And we gonna add a data record. You can add manually using database clients or you can of course make a seeder class to add dummy data like this

DB::table('posts')->insert([
  'name' => Str::random(10),
  'description' => Str::random(100),
  'created_at' => date('Y-m-d H:i:s'),
]);

Lets go to our controller and select the data with all method and print the result with dd function.

$data = Post::all();
dd($data);

The output will be look like this.

Now , let’s try to add a new column called category_id and user_id to that eloquent results. We can achieve this using map function.

$data = Post::all();

$data->map(function ($result) {
  $result->category_id = 1;
  $result->user_id = 2;
  return $result;
});

dd($data);

And the result will be look like this. Please remember there are two arrays called attributes which is the one we customized and added the data. And there is also original array which contains only original data from eloquent.

Anyhow, we can access our created data using map like always. For further more to customize the eloquent results , please check out here.

dd($data[0]->category_id.','.$data[0]->user_id);
//result -> 1,2

If you need to loop through many data, you can use loop functions but in this case I just added a 0 index to get data easily.

By Yuuma



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム