May 3, 2017

Database: Select Query: Laravel simple select query with example




On Laravel, you may not always want to select all columns from a database table.

- Here I try to explain with simple example:

Example:

$users = DB::table(<tablename>)->select('field1', 'field2')->get();

- If you want to used and alias for any field name then just used - as

$users = DB::table(<tablename>)->select('field1', 'field2 as newname')->get();

- Used 'Distinct' with Laravel select query

$users = DB::table(<tablename>)->distinct()->get();

- Sometime if you want to used other expression with SQL query

$users = DB::table(<tablename>)->select(DB::raw('count(*) as cnt, field1
                     ->where('field1', '>', 1)
                     ->groupBy('field1')
                     ->get();

Enjoy!

April 26, 2017

How to start development on Laravel?



I start to learn and developer on Laravel.

Laravel 5.4 is latest version.

Introdiction:

This quickstart guide provides a basic introduction to the Laravel framework and includes content on database migrations Blade templates. This is a great starting point if you are brand new to the Laravel framework or PHP frameworks in general.

For installation you need Composer and below is command for that:

-  composer create-project laravel/laravel quickstart --prefer-dist

You are free to quick start and download into your local machine.

You just need to write below command for easy download

git clone https://github.com/laravel/quickstart-basic quickstart
cd quickstart
composer install
php artisan migrate

If you have any of suggestion then please share it on comment please.

Enjoy!

April 11, 2017

How to get table all field's value in single word/query?


- If you want to get table all field's value in single and simple SQL query then you need to write some simple word.

- Use this simple query

Example:

SELECT * FROM <tablename>

Enjoy!

February 22, 2017

How to get SQL group_concat comma separated value sort in ASC/DESC order?



- Here is simple example to explain how to get group concat comma seprated value into order by

Example :

SELECT field1,
  GROUP_CONCAT(first_name ORDER BY first_name ASC SEPARATOR ',')
  FROM tablename

Enjoy!

January 17, 2017

Wordpress admin - How add custom column in post listing table?


- If you want to add custom column in wordpress admin all post listting, then you just need to add some function on functions.php file.

- Here I try to explain with one example like if you want to add Post ID on admin post listing page.



- Example:

File: wp-content/yourtheme/functions.php

//BELOW FUNCTION FOR DISPLAY HEADER TITLE
add_filter('manage_posts_columns', 'columns_header');

function columns_header('$default') {
 $default['post_id'] = 'Post ID';
 return $default;
}


//BELOW FUNCTION FOR DISPLAY VALUE ON THAT COLUMN

add_action('manage_posts_custom_column', 'columns_content', 10, 2);

function columns_content($column_name, $post_id) {
 if($column_name == 'post_id') {
  echo $post_id;
 }
}

Enjoy!

The Future of Technology: Emerging Trends to Watch in 2025

Introduction As we navigate through 2025, the technological landscape continues to evolve at an unprecedented pace. Innovations that once se...