Metabox – Starter Profile Form

############################################################################
// Registration Form Custom Fields Configured Here
add_filter( 'rwmb_meta_boxes', 'registration' );
function registration( $meta_boxes ) {
    $meta_boxes[] = [
        'title'  => 'Registration',
        'id'     => 'registration',
        'type'   => 'user',
        'fields' => [],
    ];
    return $meta_boxes;
}
############################################################################
function register_user_profile_fields($meta_boxes) {
    $prefix = 'user_profile_';
    // fields
    $meta_boxes[] = [
        'id'     => $prefix . 'edit_form_basic',
        'title'  => 'Your basic information',
        'type'   => 'user',
        'fields' => [
            [
                'id'   => 'first_name', // THIS
                'name' => 'First Name',
                'type' => 'text',
            ],
            [
                'id'   => 'last_name', // THIS
                'name' => 'Last Name',
                'type' => 'text',
            ],
            [
              'id'       => 'user_email',
              'type'     => 'email',
              'name'     => 'Email address',
              'readonly' => ( wp_get_current_user()->user_email ) ? true : false,
              'required' => true
            ],
            [
              'name' => 'Country Code',
              'id'   => 'mobile_country_code',
              'type' => 'text',
              'required' => true,
            ],
            [
              'name' => 'Contact Number',
              'id'   => 'user_mobile',
              'type' => 'tel',
              'required' => true,
            ],
            [
              'name' => 'Title (Job Role/Position)',
              'id'   => 'user_job_title',
              'type' => 'text',
            ],
        ],
      ];
    return $meta_boxes;
}
add_action( 'rwmb_meta_boxes', 'register_user_profile_fields',2, 1);
############################################################################
//////////////////////////////////////
//  [shortcode_avatar]  //
//////////////////////////////////////
function shortcode_avatar(){
    ob_start();
    include 'avatar.php';
    return ob_get_clean();
}
add_shortcode( 'shortcode_avatar', 'shortcode_avatar');
############################################################################

Vue / Axios Post

axios.post('/your-url-or-api-destination', payload)
.then((response) => {
  // Show Success Message
  this.$bvToast.toast('Terms and Conditions Saved', {
    title: 'Success',
    variant: 'success',
    solid: true
  });
})
.catch((error) => {
  // Show Error Message
  this.$bvToast.toast('Terms and Conditions Not Saved', {
    title: 'Error',
    variant: 'danger',
    solid: true
  });
});

Laravel Class Construct

class MyCustomClassName
{

    public function __construct()
    {
    }

    public function whatever_whatever(){
      // Code goes here. And can use anything from the construct. The construct will always load first
    }

}

Why we have classes and controllers in MVC?

A Controller or Class in MVC are both just classes.
So... Technically speaking.
It is possible to write all your functionality inside your controllers and completely ditch the classes folder.
But! The purpose of breaking out into separate classes is re-usability.

Controllers :

<?php

namespace App\Http\Controllers;

class MyCustomController extends Controller
{

}

Classes :

<?php

namespace App\Classes\MyCustomClass;

class ClassNameWhateverWhatever
{

}

Why Classes, what is the point?
-----------------------------------------------------------------
Classes serve as containers for specific purposes.
For example.

You create a class for :
Car
--
And inside your class you write all your functionality.
A car can have specific functionality.
--
moveForward()
reverse()
brake()
switchOnLights()

-----------------------------------------------------------------
Then, you reference your car class inside your contollers.
--
So something like
car->moveForward();

This design strategy makes your code extremely easy to re-use without having to re-write additional functionality. This is why we seperate everything into a class and then we create another class called a controller class and reference our classes inside the controller classes.

Laravel Save Function, update and add with exceptions

Save Function (Update and Add in 1 function based on ID)

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class RandomController extends WhateverWhateverController {

    public function saveTermsAndConditions(Request $request){
        if (isset($request->id)) {
            // Update
            try {
                DB::table('table_name')->where('id',$request->id)->update(
                    array(
                        'field'=>$request->field,
                        'content'=>$request->content,
                        'updated_at' => date("Y-m-d H:i:s", strtotime('now')),
                    )
                );
                $termsAndConditions = DB::table('table_name')->where('id', $request->id)->first();
            } catch (\Exception $e) {
                return response()->json($e);
            }
        } else {
            // Add
            try {
                $id = DB::table('table_name')->insertGetId(
                    array(
                        'field' => $request->field, 
                        'content' => $request->content, 
                        'created_at' => date("Y-m-d H:i:s", strtotime('now')),
                        'updated_at' => date("Y-m-d H:i:s", strtotime('now'))
                    )
                );
                $termsAndConditions = DB::table('table_name')->where('id', $id)->first();
            } catch (\Exception $e) {
                return response()->json($e);
            }
        }

        return $termsAndConditions;
    }
}

Laravel Raw Query The DB with Prepared Statement

Required Laravel includes

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

Select Query

class MySpecialController extends Controller
{
    public function rawQueryFunctionNameSelect(Request $request){
        $rawQuery= DB::select(
            DB::raw(
                'SELECT * FROM table_name'
            )
        );
        return $rawQuery;
    }
}

Update Query

class MySpecialController extends Controller
{
    public function rawQueryFunctionNameUpdate(Request $request){
        DB::table('table_name')->where('id',$request->id)->update(
            array(
                'field'=>$request->field,
                'content'=>$request->content,
            )
        );
    }
}

Flutter add Keystore to Github Actions as a Secret

View Full Article Here

https://proandroiddev.com/how-to-securely-build-and-sign-your-android-app-with-github-actions-ad5323452ce

2 Encoding the KeyStore

The next step treats the encoding of the KeyStore file. At this point, I assume you already own your KeyStore file. If you don’t have experience with app-signing, I suggest you take a look at the already mentioned documentation.

For encoding, we will make use of the popular Base64 encoding scheme. Base64 doesn’t stand for specific but various encoding schemes that allow you to convert binary data into a text representation.

In our case, the encoding of the KeyStorefile will allow us to store the file as text in our GitHub Secrets and later on in the GitHub Workflow process decode it back to our original KeyStore file.

The encryption step can easily be done by using OpenSSL. Download and install it, then navigate to the folder that contains your .jks file. Within the respective folder, execute the following command in your Unix terminal or just use Git bash on Windows:

openssl base64 < your_signing_keystore.jks | tr -d '\n' | tee your_signing_keystore_base64_encoded.txt

If everything went right, you should see a newly created file your_signing_keystore_base64_encoded.txt which contains a cryptic text that represents your KeyStore file.

3 The GitHub Actions Workflow

To build our CI/CD pipeline, we will use GitHub Actions. But before we can start implementing our Workflow, we first need to set up our GitHub secrets.

3.1 Set up your GitHub Secrets

In the following section, I assume that you used the identifiers from the mentioned build.gradle file. If you renamed the environment variables, you need to adapt the GitHub Secret names accordingly.

The first secret we will add is the encoded Base64 representation of our KeyStore file. To do so, go into your project's GitHub secrets and add a new GitHub Secret called KEYSTORE.

Copy the content from the your_signing_keystore_base64_encoded.txt file and paste it into the value field.

Next, create a secret that is called SIGNING_STORE_PASSWORD and contains your KeyStore password.

Afterward, create one that is called SIGNING_KEY_PASSWORD and contains your key alias password.

The last secret we need to add is called SIGNING_KEY_ALIAS and should contain the alias of your app.

3.2 The Workflow

Now that we set up our secrets, we can proceed with the actual Workflow.

Because we later want to be able to manually trigger our Workflow, we will define it as on: workflow_dispatch.

name: Build Release App Bundle

on: workflow_dispatch

To decode our encoded KeyStore file, we use the base64-to-file GitHub Action by Tim Heuer.

The GitHub Action allows us to define a parameter encodedString that will refer to our GitHub secret KEYSTORE. With the fileName parameter, we set the directory and filename of our KeyStore file in the temporary directory of our Workflow.

As we discussed in the first part of this article, our build.gradle will then be able to copy and use that file as the KeyStore.

Windows General Fix

In the Administrator: Command Prompt window, type the following commands.
Press Enter key after each command:

DISM.exe /Online /Cleanup-image /Scanhealth

DISM.exe /Online /Cleanup-image /Restorehealth

Important: When you run this command, DISM uses Windows Update to provide the files that are required to fix corruptions.
To close the Administrator: Command prompt window, type Exit, and then press Enter.
Restart your computer.