Tuesday, August 11, 2015

How to solve [ReflectionException] error in Laravel 5.1 seeding

Resolve [ReflectionException] error in seeding:

Sometimes its make a problem which we are getting in Laravel 5.1 and this is [ReflectionException]

I just got this error when i was running this command for seeding

php artisan db:seed --class=ZoneTableSeeder

and it was showing this error:

  [ReflectionException]                
  Class ZoneTableSeeder does not exist 


For solved out, I just found a solution and its working in my case.

composer dump-autoload

After that run again this command and it will work

php artisan db:seed --class=ZoneTableSeeder

 Thanks

Sunday, August 9, 2015

Easy way to set multiple seeders in Laravel 5.1

Multiple seeders in a table:

For entry multiple data in table it is a easy way to create a seeder.

For creating a seeder run the following command:

php artisan makd:seeder ClassNameSeeder

After this , in its run() function, write it

        $zones = [
            ['zone_id' => 1, 'zip' => '94133', 'rate' => '1.00'],
            ['zone_id' => 1, 'zip' => '94111', 'rate' => '2.00'],
            ['zone_id' => 1, 'zip' => '94104', 'rate' => '3.00'],
            ['zone_id' => 2, 'zip' => '94109', 'rate' => '4.00']

        ];

            \App\Zone::insert($zones);


Here the upper array is the multiple value , which you wana enter in your table.

After that run this command.

php artisan db:seed --class=ClassNameSeeder
Thanks

Friday, August 7, 2015

How and why to use Middleware in Laravel 5.1

Middleware in Laravel 5.1:

Middleware is used for check the request and then process it for particular url.

e.g. There are two types of users. One is Vendor and another is Users. Then for both kind of users will get different authorization.

For this:

Create a Middleware File

php artisan make:middleware VendorMiddleware

Now in routes.php we will set its url

route code
Route::group(['middleware' => 'auth'], function () {
    Route::get('/', ['middleware' => 'vendor', function () {
        return view('welcome');
    }]);


In VendorMiddleware:
<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class VendorMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user= Auth::user();
        if($user->user_type=='vendor'){
            echo "vendor login";
        }else{
            echo "you are unauthorized person";
        }
        //return $next($request);
    }
}


Write in app/Http/Kernel.php

 'vendor' => \App\Http\Middleware\VendorMiddleware::class,

Thanks

Friday, July 31, 2015

How to run Wordpress in a directory & its sub-directory?

Run Wordpress in Directory & Sub-Directory:

We have a wordpress site which is runnung in root directory. Now we want to install same site with different database name in subdirectory for testing purpose.

STARTING POINT:
http://www.mywordpress.com   /var/www/
http://www.mywordpress.com/foldername   /var/www/foldername

Step 1:

Put same code in /var/www/foldername as in /var/www/ . Connect it with new database.

Step 2:

Change .htaccess file in /var/www/foldername as given below

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /foldername/index.php [L]
</IfModule>

# END WordPress

At this point the configuration will not be working because the .htaccess directives at /var/www/.htaccess with be controlling all aspects of the URL so the directives at /var/www/foldername/.htaccess will have no bearing.

Step 3 :

The final step is to modify the default WordPress htaccess directives so that they will have control in for all variations of the URL.
Now change .htaccess file in /var/www as given below

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^/?foldername/$ /var/www/foldername/index.php [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Step 4:

Now login to your http://www.mywordpress.com/foldername/wp-admin/ section. Go to Setting->Permalinks.

Choose Post name in common setting.
Thanks

Friday, July 24, 2015

Join Query for multiple condition in Laravel 5.1

Join Query for Multiple Condition:

For join query in multiple condition we will use it by the following way:

DB::table('users')
        ->join('contacts', function($join) use($userId)
        {
            $join->on('users.id', '=', 'contacts.user_id')
            ->where('contacts.user_id','=',$userId);
        })
        ->get();


Also sometime we need to use condition that field is null or field is not null in where condition so we can do the following

$users = DB::table('users')
                    ->whereNull('updated_at')
                    ->get();


Thanks.

Friday, July 10, 2015

Latest ways Invite Friends on facebook using java script

Create facebook developer account & create an app in it.

Due to this you will get a API

    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'api key',
          xfbml      : true,
          version    : 'v2.2'
        });
      };
    //onclick="fbSendDialog()"
      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/en_US/sdk.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
     
      function fbSendDialog(){
      FB.ui({
      method: 'send',
      name: 'application name',
      link: 'site url'
     });
       }
    </script>
<a href="#" onclick="fbSendDialog()" > Facebook</a>

Friday, July 3, 2015

Draw map route b/w two points in php using google map api

Draw Map Route:

Pre-Requirement:- Installed PHP and web server as well JQuery working in your project.

Step 1:- Include <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.17&sensor=false"></script> in your view where you want to show map.

Step 2:- In your controller get the points in between we want to create road map route. Let the vars are $start(exp Delhi=28.6100,77.2300) and $end(exp Mumbai=18.9750,72.8258).

Step 3:-In view include the below script after the file is included

<script type="text/javascript">
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  function initialize(start,end) {
    var latlng = new google.maps.LatLng(start);
    directionsDisplay = new google.maps.DirectionsRenderer();
calcRoute();
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title:"My location"
    });
  }
  function calcRoute(start,end) {
    var request = {
      origin:start,
      destination:end,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }
</script>

Step 4:- In view take the values in hidden input fields as follows

<input type="hidden" name="start_pt" id="start_pt" value="<?php echo $start; ?>"/>
<input type="hidden" name="end_pt" id="end_pt" value="<?php echo $end; ?>"/>

Step 5:- At the end of the file include the script as follows

    <script>
      window.onload = initialize($('#start_pt').val(),$('#end_pt').val());
    </script>

Step 6:-At the end don't forgot to include the div where you want to show the map with your desired dimentions

<div id="map_canvas" style="width:710px; height:300px"></div>