Search

Code Script's Articles

Laravelcode provide all programing code core script for do something new and awosome with code.

PAN Verification In Laravel Using Sighzy API
Hello, everyone some day ago we are working with one project and in this project we are required verify PAN card details. user simple put us PAN no., Name, birth date and pind code and system return to response with this PAN card details is verify or not. so, we are done this type functionality with sighzy API. this provide best API for verify PAN details API. So, we are share with you how to integrate sighzy API in your laravel application. because they are provide document but many devloper still confuse how to integrate it in laravel application. so we are here provide very easy and best way of integration in laravel application. You Need Following Things Before start write PAN verify code you must be need one sighzy developer account. so, go on this link and create it https://signzy.com/. after create developer account you got username and password which we are use in PAN verify code for Authentication. In PAN verification we are write following 3 diffrent API login 1. Create Authentication 2. Create Identity 3. Verify PAN Card So, we are show here step by step all proccess. how to verify PAN Card. Step - 1 : Create Authentication First you need to create authentication for get Authentication userId and Id which we are also use in our Identity [ADDCODE] public function ApiAuth() { $data = array( 'username' => 'username', 'password' => 'password', ); $data_string = json_encode($data); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://signzy.tech/api/v2/patrons/login", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30000, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $data_string, CURLOPT_HTTPHEADER => array( "accept: */*", "accept-language: en-US,en;q=0.8", "content-type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return false; } else { return json_decode($response); } } Step - 2 : Create Identity After create Authentication successfully now we are create Identity for PAN. How to create it please show below code. public function Identity($Auth, $IdentityName) { $data = [ 'type' => $IdentityName, 'callbackUrl' => 'http://localhost:8000/verify-aadharcard', 'email' => 'test@gmail.com', 'images' => [ ], ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://signzy.tech/api/v2/patrons/".$Auth->userId."/identities", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30000, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => array( "accept: */*", "accept-language: en-US,en;q=0.8", "authorization:".$Auth->id, "content-type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return false; } else { return json_decode($response); } } Step - 3 : PAN Verification After done Authentication and create Identity for pan we are write PAN verification code look like this. We also use above two function in PAN verification code. public function verifyPanCard(Request $request) { // Create Authentication fo PAN API $Auth = $this->ApiAuth(); if($Auth == false) { \Session::put('errors', 'Your Aadhaar API Credentials Wrong!!'); return back(); } // Create Identity fo PAN API $Identity = $this->Identity($Auth, 'businessPan'); if(isset($Identity->error)) { \Session::put('error', 'Your Aadhaar API Identity Wrong!!'); return back(); } if($Identity == false) { \Session::put('error', 'Your Aadhaar API Identity Wrong!!'); return back(); } $data1 = [ 'service' => 'Identity', 'itemId' => $Identity->id, 'accessToken' => $Identity->accessToken, 'task' => 'verification', 'essentials' => [ 'name' => 'NAME ON PAN', 'number' => 'PAN No.', 'fuzzy' => "true", ], ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://signzy.tech/api/v2/snoops", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30000, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data1), CURLOPT_HTTPHEADER => array( "accept: */*", "accept-language: en-US,en;q=0.8", "content-type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $data = json_decode($response); dd($data); } } If you face any problem then please write a comment or give some suggestions for improvement. Thanks...
GEO Location Track In Google Map With JavaScript
Today, Laravelcode share with you how to track two starting and ending location point in google map with javascript. we are working on one transport related project in laravel and we are required this type starting and ending location point tracking in real time. we have done with javascript. Google map API provide more API functionality for google map. this tutorials also base one one of the google map API. it related to location tracking. We are write here some basic step for how to integrate location tracking in very simple way. Step : 1 Create index.php file First create one index.php file for show google map and then put into it following code. <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <title>Location Track - Laravelcode</title> <style> #map {height: 100%;} html, body { height: 100%; margin: 0; padding: 0; } #floating-panel { position: absolute; top: 10px; right: 1%; z-index: 5; background-color: #fff; border: 1px solid #999; text-align: center; } </style> </head> <body> <div id="floating-panel"> <b>Start1: </b> <input tye="text" id="start1" value="Mumbai"><!-- Starting Location --> <b>End1: </b> <input type="text" id="end1" value="Delhi"><!-- Ending Location --> </div> <div id="map"></div> <script async defer src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_MAP_API_KEY&callback=initMap&libraries=places,geometry"></script> </body> </html> After done this then copy following javascript code and also put into in after map div into script tag [ADDCODE] function calcDistance(p1, p2) {//p1 and p2 in the form of google.maps.LatLng object return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(3);//distance in KiloMeters } function getLocation() { if (navigator.geolocation) {navigator.geolocation.getCurrentPosition(showPosition, showError);} else {alert("Geolocation is not supported by this browser.");} } function showPosition(position) { alert("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude); } function showError(error) { switch(error.code) { case error.PERMISSION_DENIED: alert("User denied the request for Geolocation."); break; case error.POSITION_UNAVAILABLE: alert("Location information is unavailable."); break; case error.TIMEOUT: alert("The request to get user location timed out."); break; case error.UNKNOWN_ERROR: alert("An unknown error occurred."); break; } } function initMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: { lat: 18.9965041, lng: 72.8194209 } }); var waypts = [];//origin to destination via waypoints //waypts.push({location: 'indore', stopover: true}); function continuouslyUpdatePosition(location){//Take current location from location.php and set marker to that location var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var pos = JSON.parse(this.responseText); location.setPosition(new google.maps.LatLng(pos.lat,pos.lng)); setTimeout(function(){ continuouslyUpdatePosition(location); },5000); } }; xhttp.open("GET", "location.php", true); xhttp.send(); } /* Distance between p1 & p2 var p1 = new google.maps.LatLng(45.463688, 9.18814); var p2 = new google.maps.LatLng(46.0438317, 9.75936230000002); alert(calcDistance(p1,p2)+" Kilimeters"); */ //Make marker at any position in form of {lat,lng} function makeMarker(position /*, icon*/) { var marker = new google.maps.Marker({ position: position, map: map, /*animation: google.maps.Animation.DROP,*/ /*icon: icon,*/ }); return marker; } var icons = { end: new google.maps.MarkerImage('http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Push-Pin-1-Left-Pink-icon.png'), start: new google.maps.MarkerImage('http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Push-Pin-1-Left-Chartreuse-icon.png') }; //Show suggestions for places, requires libraries=places in the google maps api script link var autocomplete1 = new google.maps.places.Autocomplete(document.getElementById('start1')); var autocomplete2 = new google.maps.places.Autocomplete(document.getElementById('end1')); var directionsService1 = new google.maps.DirectionsService; var directionsDisplay1 = new google.maps.DirectionsRenderer({ polylineOptions: {strokeColor: "red"}, //path color //draggable: true,// change start, waypoints and destination by dragging /* Start and end marker with same image markerOptions : {icon: 'http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Push-Pin-1-Left-Pink-icon.png'}, */ //suppressMarkers: true }); directionsDisplay1.setMap(map); var onChangeHandler1 = function() {calculateAndDisplayRoute(directionsService1, directionsDisplay1, $('#start1'),$('#end1'));}; $('#start1,#end1').change(onChangeHandler1); function calculateAndDisplayRoute(directionsService, directionsDisplay, start, end) { directionsService.route({ origin: start.val(), destination: end.val(), waypoints: waypts, travelMode: 'DRIVING' }, function(response, status) { if (status === 'OK') { directionsDisplay.setDirections(response); var leg = response.routes[ 0 ].legs[ 0 ]; // Move marker along path from A to B var markers = []; for(var i=0; i<leg.steps.length; i++){ var marker = makeMarker(leg.steps[i].start_location); markers.push(marker); marker.setMap(null); } tracePath(markers, 0); var location = makeMarker(leg.steps[0].start_location); continuouslyUpdatePosition(location); } else {window.alert('Directions request failed due to ' + status);} }); } function tracePath(markers, index){// move marker along path from A to B if(index==markers.length) return; markers[index].setMap(map); setTimeout(function(){ markers[index].setMap(null); tracePath(markers, index+1); },500); } calculateAndDisplayRoute(directionsService1, directionsDisplay1, $('#start1'),$('#end1')); } Step : 2 Create location.php file Now, create one location.php file for get all dynamic location from database. we are show here static location but if you want get from database then you make it dynamic $lat = 23.6838716; $lng = 73.37194090000003; echo '{"lat":"'.$lat.'", "lng":"'.$lng.'"}'; If you face any problem then please write a comment or give some suggestions for improvement. Thanks...
Data scraping with node js and display in laravel
Hello, Everyone laravelcode today share somthing new. we are working some day ago with one laravel application and we are required some another site data to in our laravel application using data scriping. so, we are done our data scriping logic in nodejs and data display logic in laravel. here we are share one simple example demo for data scraping with nodejss and how to display in laravel application Today, in IT world day by day required something do new. but sometime some functionality code write into php is very difficult(but not imposible) and we are write that code login in another technology and then after merge. this method is very good for better performance for site. Nodejs and laravel currently most famous framework for web-development and today many project develope using nodejs and laravel in one platform. for example real time chat system is best example for it. Many laravel developer did't knowing how to use nodejs in laravel application. so we are share here one tutorials may be it's more helpfull to you for how to start nodejs setup in laravel and some basic stuff We are starting here to install node and how to use with laravel application step by step Our scraping data dispay preview look like Step : 1 Install node js For this tutorial we are required node so first we are install node in our local system. sumple run following command in your terminal. sudo apt-get update sudo apt-get install nodejs sudo apt-get install npm Check node version node -v Check npm version npm -v Step : 2 Create one laravel application After install node js then we are required creae one laravel dummy application run by following command. composer create-project --prefer-dist laravel/laravel LaravelWithNodeJs After successfully create laravel aplication then configure you database, user and password in .env file. Step : 3 Install npm package dependency Open your laravel project root directory's package.json file and add following dependency in this file like that. "devDependencies": { ------- ------- "express" : "latest", "request" : "latest", "cheerio" : "latest" } After add above dependency then after run following command to install it in our laravel project directory sudo npm install After run this command then check in your project directory here created node_modules folder automatic and your all npm and node dependency installed there. Step : 4 Check node js working Now how to check our node js code working in our application or not. so first create file node/server.js and simply write followign code for testing. var express = require('express'); var app = express(); app.listen('8001'); console.log('Your node server start....'); exports = module.exports = app; Then after goto your project_derectory/node path and run folloeing command sudo node server.js If after run this command and you sow "Your node server start...." this output string then your node js code perfect work/run in your local system. Step : 5 Write nodejs scraping code Now we are write our target site scraping code in nodejs. here we are targeting https://news.ycombinator.com this website for demo. Before starting write nodejs scraping script first show following html structure which use in our targeting https://news.ycombinator.com site <td class="title"> <a href="link" class="storylink"> title </a> <span class="sitebit comhead"> ( <a href="from?site=decisionsciencenews.com"> <span class="sitestr">decisionsciencenews.com</span> </a>) </span> </td> In this nodejs scraping code we are targetin span.comhead html dome and scraping following structured data 1) rank 2) title 3) url 4) points 5) username 6) comments Now open your node/server.js file and put following nodejs scraping code. [ADDCODE] var express = require('express'); var fs = require('fs'); var request = require('request'); var cheerio = require('cheerio'); var app = express(); //Scraping start app.get('/scrape', function(req, res){ request('https://news.ycombinator.com', function (error, response, html) { if (!error && response.statusCode == 200) { var $ = cheerio.load(html); var parsedResults = []; $('span.comhead').each(function(i, element){ // Select the previous element var a = $(this).prev(); // Get the rank by parsing the element two levels above the "a" element var rank = a.parent().parent().text(); // Parse the link title var title = a.text(); // Parse the href attribute from the "a" element var url = a.attr('href'); // Get the subtext children from the next row in the HTML table. var subtext = a.parent().parent().next().children('.subtext').children(); // Extract the relevant data from the children var points = $(subtext).eq(0).text(); var username = $(subtext).eq(1).text(); var comments = $(subtext).eq(2).text(); // Our parsed meta data object var metadata = { rank: parseInt(rank), title: title, url: url, points: parseInt(points), username: username, comments: parseInt(comments) }; // Push meta-data into parsedResults array parsedResults.push(metadata); }); // Log our finished parse results in the terminal console.log(parsedResults); } fs.writeFile('../public/output.json', JSON.stringify(parsedResults, null, 4), function(err){ console.log('Sraping data successfully written! - Check your project public/output.json file'); }); res.send('Scraping Done...'); }); }); app.listen('8001'); console.log('Your node server start successfully....'); exports = module.exports = app; Then after goto your project_derectory/node path and run folloeing command sudo node server.js After starting node server then open your browser and type following url localhost:8001/scrape after run this url in browser you got this message in browser window"Scraping Done..." now your data scraping done. then check your terminal here you also getting one message like thatSraping data successfully written! - Check your project public/output.json file Now we are done data scraping proccess and our data scraping file automatic write in json formate data in public/output.json file. now how to display this data in our laravel application front site. simple follow this step. Step : 6 Create route First create one route for a view/blade file like that Route::get('data-scraping', 'DataScrapingController@index'); Step : 7 Create controller now create DataScrapingController.php file look like namespace App\Http\Controllers; use App\Http\Requests; use Illuminate\Http\Request; use DB; use Session; class DataScrapingController extends Controller { public function index() { $data = json_decode(file_get_contents('output.json')); return view('data-scraping', compact('data')); } } Step : 8 Create blade/view file Into the last create resources/views/data-scraping.blade.php file and write html code like that for display data. @extends('layouts.app') @section('content') <div class="container"> @foreach($data as $key => $value) <div class="col-sm-12"> <a href="{!! $value->url !!}"> <h3 class="title">{!! $value->title !!}</h3> </a> <p class="text-muted"> <strong>Points :</strong> {!! $value->points !!} <strong>Comments :</strong> {!! $value->comments !!} </p> <p class="text-muted">Posted by <a href="#">{!! $value->username !!}</a></p> </div> @endforeach </div> @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/data-scraping We are hope it can help you...
PHP - How to get filename from N-level file directories
In this tutorials we are share with you one php code script related how to get filename from N-level derectory structure in php. we are always do somthing with php code and then share with every one. This tutorials base on php file handling concept. [ADDCODE] <?php ini_set('max_execution_time', 0); set_time_limit(0); /* |============================================================| |get file name in N-level directory structur | |============================================================| */ function getDirContents($dir, &$results = array()){ $files = scandir($dir); foreach($files as $key => $value){ $path = realpath($dir.DIRECTORY_SEPARATOR.$value); if(!is_dir($path)) { $results[] = $path; } else if($value != "." && $value != "..") { getDirContents($path, $results); $results[] = $path; } } return $results; } // $filesandfolderlist = listFolderFiles('target_folder_name'); $fileslist = getDirContents('target_folder_name'); echo " "; print_r($fileslist);exit; We are hope you are like this script, if any query please comment bellow.