laravel 4.2 How to convert my php codes into laravel standards -


i'm trying convert php codes laravel standard, want add controller , render view. php code works fine it's function determine distance between 2 points. want convert php codes laravel standards, in simple way. knows how it? in advance. here's codes:

<?php function getdistance($latrider,$lontrider,$latdriver,$londriver){     $earthradius=6371;     $latfrom=deg2rad($latrider);     $lonfrom=deg2rad($lontrider);      $latto=deg2rad($latdriver);     $lonto=deg2rad($londriver);      $latdelta=$latto-$latfrom;     $londelta=$lonto-$lonfrom;      $angle=2*asin(sqrt(pow(sin($latdelta/2),2)+         cos($latfrom)*cos($latto)*pow(sin($londelta/2),2)));     return $angle*$earthradius; }  $latrider=11.707389; $lontrider=122.37194309999995;  $latdriver=11.7105254; $londriver=122.36308980000001;  $distance=getdistance($latrider,$lontrider,$latdriver,$londriver); echo"distance between rider position , driver position is:".$distance."km"; ?> 

the code in controller should :

<?php namespace app\http\controllers;  use app;  use illuminate\http\request; use app\http\controllers\controller;  class yourcontroller extends controller {      private function getdistance($latrider,$lontrider,$latdriver,$londriver) {         $earthradius=6371;         $latfrom=deg2rad($latrider);         $lonfrom=deg2rad($lontrider);          $latto=deg2rad($latdriver);         $lonto=deg2rad($londriver);          $latdelta=$latto-$latfrom;         $londelta=$lonto-$lonfrom;          $angle=2*asin(sqrt(pow(sin($latdelta/2),2)+             cos($latfrom)*cos($latto)*pow(sin($londelta/2),2)));         return $angle*$earthradius;     }      public function index (request $request) {          $latrider=11.707389;         $lontrider=122.37194309999995;          $latdriver=11.7105254;         $londriver=122.36308980000001;          $data = array(              'distance' => $this->getdistance($latrider,$lontrider,$latdriver,$londriver)         );          return view('your-view')->with($data);     }  } 

you need add corresponding route in app/http/route.php :

 route::get( '/your-route', ['uses' => 'yourcontroller@index']); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -