I’m a complete layman in laravel , and now I’m laravel for what
I had the function 1.php :
require_once('include/config.php'); require_once('include/func.php'); require_once('include/class_header.php'); function GPSOnline ($gpsonline){ $gpsonline= getHTTPGPSOnline(); $fstep = explode("|", $gpsonline); foreach($fstep as $k => $v){ if(strlen($v)>0){ $sstep [] = explode(",", $v);// создаем 2у мерный массив } } $array = array(); foreach ($sstep as $v){ $tmp['login'] = $v[0]; $tmp['ch'] = substr($v[0],0,1); $tmp['poz'] = substr($v[0],1); $tmp['la'] = $v[1]; $tmp['lo'] = $v[2]; $array[] = $tmp;// ключем нового многомерного масиива явлеться 0 элемент массива $sstep } echo json_encode($array); }} GPSOnline(); Everything works fine and gives me the necessary data! Next, this function was accessed by an AJAX request in the parameters of which was specified:
url: "/1.php" Question : How can I transfer my 1.php function to the newly created method in the laravel framework and change the url value in the AJAX request (ie, change url: "/1.php" to url:"ссылка на метод laravel" ?
After sitting on the forums I registered a new class and added a method to it:
public function GPSOnline () { $gpsonline=File::get( Config::get('app.driverspath')); $fstep = explode("|", $gpsonline); foreach($fstep as $k => $v){ if(strlen($v)>0){ $sstep [] = explode(",", $v); } } $array = array(); foreach ($sstep as $v){ $tmp['ch'] = substr($v[0],0,1); $tmp['poz'] = substr($v[0],1); $tmp['la'] = $v[1]; $tmp['lo'] = $v[2]; $array[] = $tmp; } // echo json_encode($array); return Response::json(array($array)); } In the AJAX request, I wrote to the source url:
url:"{{URL::action('GpsController@GPSOnline')}}" But it still does not work, it seems to me that I did not correctly register the GPSOnline method ?!
What needs to be fixed?