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



アプリ関連ニュース

お問い合わせはこちら

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

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

お問い合わせフォーム