Posts

Showing posts from June, 2014

How to write MySql Query in laravel?

I will show a simple query in laravel where you can easily understand that how query works in laravel 4. $limit = 5; $value= Bank::where('isactive','=','yes')->where('money','>',0)->whereNotNull('account')->whereNull('credit')->take($limit)->orderBy('id', 'DESC')->get(); This query act like as query below select * from Bank where money>0 amd account!=null and credit='' order by id desc limit 0,5. This is the representation that how laravel query works i added here where condition with 3 different ways and limti and order by for this query This query will work for both Database MYSQL MongoDB

How to get XML response output in laravel?

How to get XML response output in laravel? or How to create XML response output in laravel? or Most of developers use header function to create xml file but this does not work header('Content-type: application/xml'); $output  = "<?xml version='1.0' encoding='UTF-8'?>"; here i will tell you that how can you show or save XML response output in laravel you have an array where you have data Here is an example that how can you create xml file response in laravel suppose you have an array which have twitter data //Preapre our output for xml data $output  = "<?xml version='1.0' encoding='UTF-8'?>"; $output .= "\n<twitterfeed>\n"; $j=0; foreach($twitterinfo as $row){ $j++; $output .= "<feed>\n"; $output .= "<id>" . $j . "</id>\n"; $output .= "<twitter_id>" . $row['twitter_id'] . "</twitter_id>\n"

How to rename a field from a collection in mongoDB?

How to rename a field from a collection in mongoDB? By this query you can rename a field from whole collection in mongoDB db.colleciton.update(     //  where query like: where active="yes"     {         "active" : "yes"     },       // will remove Name field from current collection     {         $rename: {"Name":"Username"}     },       // options     {         "multi" : true  // update all document     } ); or you can copy and paste this code above code is with comment that how mongoDB query works db.colleciton.update(     {         "active" : "yes"     },     {         $rename: {"Name":"Username"}     },     {         "multi" : true     } );

How to remove a field from a collection in mongoDB?

How to remove a field from a collection in mongoDB? By this query you can remove a field from whole collection in mongoDB db.colleciton.update(     //  where query like: where active="yes"     {         "active" : "yes"     },         // will remove Name field from current collection     {         $unset: {"Name":""}     },         // options     {         "multi" : true  // update all document     } ); or you can copy and paste this code above code is with comment that how mongoDB query works db.colleciton.update(     {         "active" : "yes"     },     {         $unset: {"Name":""}     },     {         "multi" : true     } );

EntityRef: expecting ';' error while creating the xml file?

This page contains the following errors: error on line 68 at column 18: EntityRef: expecting ';' Below is a rendering of the page up to the first error. Generally  this error occured when any value have & in the value between tag example:  <Name>PHP & C</Name> So & break the xml and due to this it shows the error just replace   & with  &amp   in your value field example:  $output .= "<Name>" . str_replace('&', '&amp;', $row['name']) . "</Name>"; I hope this will help you. If helped then dont forget to comment to inspire me :)

No hint path defined for [folder] in laravel?

No hint path defined for [folder] in laravel. There could be several reasone for this error in laravel. But most of time it works like a charm to solve this probelm - No hint path defined for If you will check your view file which you have include in your controller or routes. then  you will find that on view file you have some code like this in your view/file.php @extends('Folder::layouts.default') Or @include('Folder::includes.header') to pass the view in templates so where folder is mention you can change the folder  path where your file is located.

How to remove blank array from an array?

How to remove blank array  from an array? like: you have an array where a key is blank and you want to remove the array from the tree of array then you can use this function like: function unsetblankarray($array)     {         foreach($array as $key=>$value)         {             if(!@$array[$key]['field'])             {                 unset($array[$key]);             }         }         return $array; }

How to get the input value after validation failed in laravel 4?

You can get the particular input field after validation failed in laravel 4. simple use the old method with Input class to get the last inserted value of input box. $getvalue = Input::old("fieldName");

How to create a table via Artisan in laravel?

Create a table in database via Artisan in laravel Step1: First you need to go on your root directory Step2: php artisan migrate:make create_users_table paste this code into your command interface Step3: Check the file named 2014_mm_dd_114554_create_users_table.php in your Root\app\database\migrations folder Step4: There will be two method Up and Down paste this Schema in this method  public function up()     {         //         Schema::create('users', function($table)         {             $table->increments('id');             $table->string('email')->unique();             $table->string('name');             $table->timestamps();         });     }     /**      * Reverse the migrations.      *      * @return void      */     public function down()     {         //         Schema::drop('users');     } Step5: Run this command on your root directory php artisan migrate You  can check the database there will a

How to set flash message in laravel?

Set flash message in laravel You need to add this code in your controller Session::flash('loginerror', "Your Email-id or Password does not match."); return Redirect::to('login'); Now you need to add this code in your view section @if (Session::has('loginerror'))    <h2>{{ Session::get('loginerror') }}</h2> @endif

How to check php version in Linux?

How to check php version in Linux or centos simple copy and paste this command to check the php version in your linux window php -i | grep 'PHP Version' Output: PHP Version => 5.5.10