Thursday, 31 March 2016

Get All First Letters or Abbreviation of Each Words of the sentence as a Abbreviated String using PHP

Please use the below function to pull all First Letters of Each Words of the sentence as a abbreviated String using PHP.

 * Get the first letters or abbreviation of each words and as a uppercase string format.
 * @param $string Pass the parsing string
 * @return string String
function getFirstLettersOfWords($string) {}
function getStringAbbreviation($string) 
 // Match the first letters of each words using regular expression.
 $matchFound= preg_match_all('/(\w)(\w+)/', $string, $matches);

 // Concatenate all the matched first letters as a string in upper case.
 $abbreviatedString= strtoupper( implode('', $matches[1]) );

 return $abbreviatedString;

Function Usage

$string1 = 'Distributor / Sub-Distributor';
$output1 = getStringAbbreviation($string1);

// Output: DSD

$string2 = 'Consultant (Registration, Licensing, Visa)';
$output2 = getStringAbbreviation($string2);

// Output: CRLV

Tuesday, 29 March 2016

Create the migrations for database views using php artisan in Laravel

Please follow the steps to create a sql views for Laravel using PHP Artisan using below step.

Step 1. Run below command:
php artisan make:migration create__views

Step 2. Open the migration file and add the below code:
    * Run the migrations.
    * @return void
    public function up()
      CREATE VIEW views_overall_status AS
       SELECT AS auth_users_entity_roles_id, er.auth_users_id,
        e.checklists_id, c.overall_status_id AS status_id, AS status_name
       FROM `auth_users_entity_roles` er
        LEFT JOIN entities e ON
        LEFT JOIN `checklists` c ON
        LEFT JOIN `status` s ON = c.overall_status_id
       WHERE s.slug = 'operating_risks' AND e.deleted_at IS NULL
        AND c.deleted_at IS NULL
    * Reverse the migrations.
    * @return void
    public function down()
     DB::statement('DROP VIEW IF EXISTS views_overall_status');

Step 3. To call and run the SQL Views via Laravel query
    $items = $DB::table('views_entities_by_overall_status')
                ->select('status_id', 'status_name', 'status_name_trans_text_id',
                    $DB::raw('count(entities_id) as counts')
                ->orderBy('counts' , 'desc')
                ->whereIn('entities_id', Auth::user()->getEntityRoleEntityIDs())

Hope that helps. Please let me know if anyone has better solution!!

Friday, 18 March 2016

How to User Current Version of Syntax Highlighter on Google Blogger

In order to install & use it on Google Blogger, follow the below steps:
  • First, go to your Template Layout-> Backup/ Restore  on the top right of the page to download your template as a backup.
  • After downloading your template, then click Edit HTML for Layout & then paste the below code in your Template before your < / head > tag ends.
Note: This below information is for the integrating the latest released (current) version; more information can be found at:


Please let me know if you need further information.

Thursday, 10 March 2016

To Write a Sample Join Query in Laravel 5.2

Please follow the example below to write the the Multiple Join Query on Laravel 5.2
// NOTE: Please do not forgot add below line at the top to use DB instance
$whereClause = array( $this->table.".checklists_id" => 1 );
$items = DB::table($this->table)
->join('approval_states', '', '=', $this->table.'.approval_state_id')
->join('approval_levels', '', '=', 'approval_level_conditions.approval_levels_id')
 ' as level_name', 'approval_levels.level',
 DB::raw("IF( approval_states.state='Approved','1','0' ) AS state_value")
->where($this->table.'.deleted_at', null) // to ignore the soft deleted records.

Output Query (will produce the following JOIN query):
SELECT `approval_checklists`.*, `approval_levels`.`name` AS `level_name`, `approval_levels`.`level`, `approval_states`.`state`, 
IF( approval_states.state='Approved','1','0' ) AS state_value FROM `approval_checklists` 
INNER JOIN `approval_states` ON `approval_states`.`id` = `approval_checklists`.`approval_state_id` 
INNER JOIN `approval_levels` ON `approval_levels`.`id` = `approval_level_conditions`.`approval_levels_id` 
WHERE (`approval_levels`.`checklists_id` = 1) 
AND `approval_checklists`.`deleted_at` IS NULL

Hope it helps!!!

Writing the Subquery in Laravel 5.2

Please follow the example below to write the the Sub Query on Laravel 5.2:
// NOTE: Please do not forgot add below line at the top to use DB instance
$result = static::select('id')
->where( 'id', '!=', $currentLevelId)
->where('level', '>', DB::raw("(SELECT level FROM " . $this->table . " WHERE id='".$currentLevelId."')") )

Will produce the below subquery:
SELECT * FROM `approval_levels` WHERE `id` != 2 AND `level` > (SELECT LEVEL
FROM approval_levels WHERE id='2') ORDER BY `level` ASC LIMIT 1
Another Example:
$data = DB::table("items")
   GROUP_CONCAT(items_count.price) as price_group,
   FROM items_count
   ) as items_count"),function($join){

Hope it helps!