Unique Validation on update in laravel

Create below rule to check the unique on update in laravel

$rules = array('email' => 'required|unique:users,email,[Enter Id here]');
$validator = Validator::make(Input::all(), $rules);

Get column name and its information from table in mysql

Please write below query:

select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, 
       NUMERIC_PRECISION, DATETIME_PRECISION, 
       IS_NULLABLE 
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'

Laravel Database Migration

Please follow these steps to create successful migration.

1) Please run this command to create migration file
php artisan migrate:make create_users_table

2) You can check the migration file in folder app/database/migrations (File name: eg 2014_12_01_064050_create_users_table.php)

3) You can add the table fields in this file with proper syntax.

4) Run this command

php artisan migrate

Note: If table is not created then please give the 777 permission to migration file.

How to redirect the site to m.example.com

How to redirect the site to m.example.com when you are running the site on mobile device -

#‪#‎BEGIN‬ MOBILE (do not edit below this line)
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ((.*iPhone.*)|(.*iPod.*)|(.*BlackBerry.*)|(.*Android.*Mobile.*)|(.*Windows\ CE.*)|(.*IEMobile.*)|(.*Opera\ Mini.*)|(.*Opera\ Mobi.*))
RewriteCond %{HTTP_COOKIE} !dm_show_classic
RewriteCond %{QUERY_STRING} !no_redirect=true [NC]
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTP_HOST} ^[0-9a-z-]+\.[a-z]+$ [NC]
RewriteCond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
RewriteBase /
RewriteRule ^(.*)$ http://m.example.com/ [R,L]
#‪#‎END‬ MOBILE

Q. What is Magento?


A. Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magento’s intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Varien's support network, Magento offers companies the ultimate eCommerce solution.

Get The Current Category in Magento

Try below code to get currently loaded product id:

$category_id = Mage::getSingleton('catalog/layer')
               ->getCurrentCategory()
               ->getId();

When you don’t have access to $this, you can use Magento registry:

$category_id = Mage::registry('current_category')->getId();

Redirect Website to a particular file

1) create a file which file you want to redirect(eg. filename.php).
2) create .htaccess file.
3) add the following code in the .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ filename.php [NC,L]

Get posts in wordpress


Use following code  for get the posts:

$args = array(
'posts_per_page'   => 5,
'offset'           => 0,
'category'         => '',
'orderby'          => 'post_date',
'order'            => 'DESC',
'include'          => '',
'exclude'          => '',
'meta_key'         => '',
'meta_value'       => '',
'post_type'        => 'post',
'post_mime_type'   => '',
'post_parent'      => '',
'post_status'      => 'publish',
'suppress_filters' => true );

$posts_array = get_posts( $args );

How to change the Magento Admin URL / Path

Step 1 - Change Path

First, open the local.xml configuration file in your favorite text editor, or use the Text Editor in the cPanel File Manager. The file is usually located in the app/etc/ directory under your Magento installation. Locate the following code segment:

<frontname><![CDATA[admin]]></frontname>


Now, replace admin with your new admin path. This should be something personal which is hard to guess, use only letters or numbers - no special characters, then save the file.

Step 2 - Refresh Cache

The final step is to refresh your cache. Use an FTP client to delete the content of the var/cache/ directory, 

Create pyramid of stars in PHP.

Program in PHP:
function create_pyramid($limit) {
    for($row = 1; $row < $limit; $row ++) {
        for($j = 0; $j < $limit-$row; $j++){
        echo " ";
        }
        for($k = 0; $k < ($row-1)*2+1; $k++){
        echo "*";
        }
       echo 'break tag here';
    }
     $s = 2;
    for($l=$row-1; $l>0; $l--){
        for($m = 0;$m<$s; $m++){
        echo " ";
        }
   
        for($n = 0; $n < ($l-1)*2-1; $n++){
        echo "*";
        }       
       echo 'break tag here';
       $s++;
    }
}
echo " break tag here" ;
create_pyramid(10);


Output:

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *
          
Fibonacci Series:

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it.
Program in PHP:

$a = 1; $b=0; $series = 0;
   for($i=0;$i<=7;$i++)
{
    echo $series;
    $series =$a+$b;
    $a = $b;
    $b = $series;
}

Prime Number Program in PHP.

Prime Number: 
                             A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, 5 is prime because only 1 and 5 evenly divide it, whereas 6 is composite because it has the divisors 2 and 3 in addition to 1 and 6.

Program in PHP:  

$num =100;
for( $j = 2; $j <= $num; $j++ )
{
for( $k = 2; $k < $j; $k++ )
{
if( $j % $k == 0 )
{
break;
}

}
if( $k == $j )
echo "Prime number: ".$j."
";
}

Enable WSDL Cache in Magento

To Enable WSDL Cache in magento follow these steps:

1)  Login to admin panel.
2) Go to System > Configration > Services >Magento Core API
3) Select 'yes' to Enable WSDL Cache.

4) Click on  'Save Config' button.

Enable Magento Template hints in admin


You might not have thought it was possible to enable template path hints in admin, but it is!

1
2
3
INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);
To disable them again, run this query
1
UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints'
To enable again run this query
1
UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints'

Create Static block in Magento:

To create static block follow these steps:

1) Click on “static block” under cms menu in admin panel.
2) Click on “Add new block” button.
3) Enter Block title and block identifier.
4) Select store view and status.
5) Enter all the code related to block in editor.
6) Click on “Save Block” button.

Create or modify Email Template in Magento

There are two options for create or modify a email template.


1) By changing template file in /app/locale/en_US/template/email folder.
2) By creating custom template from admin panel.

To create custom email template from admin panel follow these steps:

1) Click on “Transactional Emails” under system menu.
2) Click on “Add new Template” button.
3) Load a default template from dropdown e.g. New Account
4) After loading the template make changes in this template according your requirement.
5) Add template name.
6) Save the template.

To apply this template to particular mail follows these steps:

1) Click on “configuration” under system menu.
2) Choose “customer configuration” to apply custom template to “new account” mail.
3) Select a custom email from dropdown under “Create new account” option.
4) Click on “Save config” button.

URL Rewrite in Magento



This is used to redirect category navigation to another custom url.

For URL Rewrite follow these steps:
  1. Login to admin panel.
  2. Click on “URL Rewrite Management” under catalog menu.
  3. Select a category to redirect a URL.
  4. Copy ID path and Request path.
  5. Delete particular category.
  6. Create new custom rule.
  7. Enter ID path and request path.
  8. Enter your Target path and select permanent redirect.
  9. Click on Save button.

PHP uniqid() function


Definition and Usage

The uniqid() function generates a unique ID based on the microtime (current time in microseconds).


Syntax

uniqid(prefix,more_entropy)


Parameter Description
prefix Optional. Specifies a prefix to the unique ID (useful if two scripts generate ids at exactly the same microsecond)Note: This parameter became optional in PHP 5
more_entropy Optional. Specifies more entropy at the end of the return value. This will make the result more unique. When set to TRUE, the return string will be 23 characters. Default
is FALSE, and the return string will be 13 characters long 

Example

echo uniqid();


The output of the code above could be:
4415297e3af8c