Monday, 20 March 2017

Username validation using Regis on Laravel

Please find the validation script below to fix the username validation allowing it to have only Alphanumeric with dot (.), dash/hypen (-) and underscore(_).

$validator = Validator::make($request->all(),
            ['user_name' =>
                ['required', 'min:4', 'max:20', 'unique:auth_users', 'Regex:/^[a-zA-Z0-9-._]+$/']
            ]


Thursday, 15 December 2016

Configure the Project Specific Git Author/User Credential

If you working for two projects (may be one for work specific and another personal project) and you would like to configure the Git Author/User credential different for both, I mean as a project specific rather than as a global one.

You may have configured or can set as global credential as:
# To check the git configuration
git config -l

# To set the global git configuration
git config --global user.name "RC"
git config --global user.email "rc@example.com"
Now to change the credential for a project. First go the the project branch and check what's the credential it has and override with new credential using below command
# Go to the project folder first and make sure you already have git initiated.
cd ~/apps/project_folder

# To check the git configuration
git config -l

# To overwrite the name
git config user.name "RC Pro"

# To overwrite the email
git config user.email "personal@example.com"

Then, you all set for that.

Check Git for more

Monday, 26 September 2016

AngularJS filter to Translate input and replace variable separately afterwards into the translated input

Translate input and replace the variable afterwards on the string with variable placeholder ie. [variable].

First create AngularJs filter fiel called translate-input-var-and-replace.js and save with below content:
/* Translate input and replace the variable afterwards on the string with variable placeholder ie. [variable]. */
myapp.filter('translateInputWithVarReplace', ['$filter', function($filter) {
    return function(input, replaceVariable) {
        input = $filter('translate')(input);
        return input.replace(RegExp(/\[(.*?)\]/g), replaceVariable);
    };
}]);


Usage:
// The 'translated_string' should have the value containing the [variable] in the string. 
// translated_string = 'There will be [variable] people watching this movie.';

 var output = $filter('translateInputWithVarReplace')('translated_string', '545');

Expected Output:
There will be 545 people watching this movie.

Merging two or more JavaScript Objects using AngularJS

Please use below steps to merge two or more JavaScript Objects using AngularJS

// Object one
var jsObjectA = {title:'Buddha is born in Nepal', famous:'Gautum Buddha', country:'Nepal', district:'Bhirawa'};

// Object two
var jsObjectB = {religion:'Buddhism', zone:'Lumbini', district:'Kapilvastu'};

// Merging above two objects
var mergeObject = angular.extend({}, jsObjectA, jsObjectB); 

Expected Output:
{title:'Buddha is born in Nepal', famous:'Gautum Buddha', country:'Nepal', religion:'Buddhism', zone:'Lumbini', district:'Kapilvastu'};

Tuesday, 30 August 2016

AngularJS String Replace filter in the Template File

Please find follow the below steps to replace the string on the Template file using AngularJS filter:

1. Create the filter file called string-replace.js and add the following code.
myapp.filter('stringReplace', [ function() {
    return function(input, search, replace) {
        input = input.split(search);
        
        var x;
        var result = '';
        var prefix = '';
        for (x in input ) {
            result += prefix + input[x];
            prefix = replace;
        }

        return result;
        //return input.replace(search, replace);
    };
}]);

2. Then, in html template file, adopt the below example to use the filer.
{{your_string_variable_here | stringReplace:'searchParameterHere':'replaceParameterHere'}}

Example:
{{"GLOBAL_WARMING_NEEDS_TO_CONTROL_BY_EVERYONE" | stringReplace:'_':'-'}}

Output: GLOBAL-WARMING-NEEDS-TO-CONTROL-BY-EVERYONE

Monday, 6 June 2016

Resolving the issue with Gulp "Warning: gulp version mismatch:"

If you are getting the following types error:
[14:32:54] Warning: gulp version mismatch:
[14:32:54] Global gulp is 3.9.1
[14:32:54] Local gulp is 3.9.0
[14:32:56] Using gulpfile C:\xampp\htdocs\myproject\gulpfile.js
[14:32:56] Starting 'default'...
[14:32:56] Starting 'scripts'...
To resolve the issue,
First, go to your project root folder then run below two commands
npm update gulp -g 
npm update gulp

Thursday, 12 May 2016

List of Laravel Artisan Shortcuts (Alias) for Windows and MacOS

I would like to share the list of command alias I have created on my local to minimise the keystrokes with the Team.

Please go to the project root location via command line and just copy the below line (one line string) and run it:

alias cda="composer dump-autoload"; alias ci="composer install"; alias cu="composer update"; alias bi="bower install"; alias bu="bower update"; alias gi="gulp install"; alias ni="npm install"; alias pa="php artisan"; alias pam="php artisan migrate"; alias pamr="php artisan migrate:rollback"; alias pads="php artisan db:seed"; alias pades="php artisan db-exporter:seed"; alias pamm="php artisan make:migration"; alias pamc="php artisan make:controller"; alias pammd="php artisan make:model"; alias t="phpunit"; alias dat="php artisan app:droptables"; alias ga="git add"; alias gaa="git add ."; alias gc="git commit -m"; alias gp="git push"; alias gs="git status"; alias gl="git log"

The detail of the above string shortcut is below (if you want other way, feel free to change it with your comfort):

#Composer
alias cda="composer dump-autoload"
alias ci="composer install"
alias cu="composer update"

# Bower
alias bi="bower install"
alias bu="bower update"

# Gulp
alias gi="gulp install"
alias ggw="gulp && gulp watch"
# NPM alias ni="npm install" # Laravel alias pa="php artisan" alias pam="php artisan migrate" alias pamr="php artisan migrate:rollback" alias pads="php artisan db:seed" alias pades="php artisan db-exporter:seed" alias pamm="php artisan make:migration" alias pamc="php artisan make:controller" alias pammd="php artisan make:model" alias t="phpunit" # Laravel Custom alias dat="php artisan app:droptables" # Git alias ga="git add" alias gaa="git add ." alias gc="git commit -m" alias gp="git push" alias gs="git status" alias gl="git log"