Reputation: 58702
I have code running perfectly fine on Laravel 5.1
I'm in the process of trying to upgrade from 5.1
. to 5.7
Compiler seems to complain about this line here :
use App\Visitor, App\CURLexec;
meta.blade.php
<meta charset="utf-8">
@if( App::environment('local') )
<title>local</title>
@else
<title>Author</title>
@endif
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Author">
<meta name="csrf-token" value="{{ csrf_token() }}">
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<!-- HTML5 shiv and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/plugins/html5shiv.js"></script>
<script src="js/plugins/respond.min.js"></script>
<![endif]-->
<?php
use App\Visitor, App\CURLexec;
if (!function_exists('getallheaders'))
{
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
$ip = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com")); Debug::console($ip);
$ip = $_SERVER['REMOTE_ADDR'];
$info = shell_exec('curl ipinfo.io/'.$ip );
$ip_info_array = json_decode($info,true);
$header_info = getallheaders();
$loc = isset($ip_info_array['loc'])? $ip_info_array['loc'] : '';
$url = 'https://maps.google.com/maps/api/geocode/json?latlng='. $loc .'&sensor=false';
$geocode_array = CURLexec::get($url);
$formatted_address = isset($geocode_array['results']['0']['formatted_address'])? $geocode_array['results']['0']['formatted_address'] : '';
$place_id = isset($geocode_array['results']['0']['place_id'])? $geocode_array['results']['0']['place_id'] :'';
$formatted_address = isset($geocode_array['results']['0']['formatted_address'])? $geocode_array['results']['0']['formatted_address'] : '';
$place_id = isset($geocode_array['results']['0']['place_id'])? $geocode_array['results']['0']['place_id'] : '';
//Mac Address + Inet
$env = Request::server ("HTTP_HOST"); //localhost:8888
if ($env == 'localhost:8888'){
//Local
$inet = trim(shell_exec("ifconfig en0 | grep 'netmask' | awk '{print $2}'"),"\n");
$grab_bssid_command = 'arp '.$inet.' | awk \'{print $4}\'';
$bssid = trim(shell_exec($grab_bssid_command), "\n");
}else{
//Other Machine/Server
$inet = $ip;
$grab_bssid_command = 'arp '.$inet.' | awk \'{print $4}\'';
// dd($grab_bssid_command);
$bssid = trim(shell_exec($grab_bssid_command), "\n");
}
// LatLong Map http://maps.google.com/?q=-27.0000,133.0000
// Static Map = http://maps.google.com/maps/api/staticmap?center=40.7421,-74.0018&zoom=13&size=500x300
$static_map_url = 'https://maps.google.com/maps/api/staticmap?center='. $loc.'&zoom=13&size=500x300&maptype=roadmap&scale=2
&markers=size:mid|color:red|'. $loc .'|size:small';
$map_url = 'https://maps.google.com/?q='. $loc;
$ip = isset($ip_info_array['ip'])? $ip_info_array['ip'] : '';
$host_name = isset($ip_info_array['hostname'])? $ip_info_array['hostname'] : '';
$city = isset($ip_info_array['city'])? $ip_info_array['city'] : '';
$region = isset($ip_info_array['region'])? $ip_info_array['region'] : '';
$country = isset($ip_info_array['country'])? $ip_info_array['country'] : '';
$org = isset($ip_info_array['org'])? $ip_info_array['org'] : '';
$postal = isset($ip_info_array['postal'])? $ip_info_array['postal'] : '';
//User Agent
$user_agent_info = isset($header_info['User-Agent'])? $header_info['User-Agent'] : '';
$user_agent_array = ( explode(";",$user_agent_info));
//OS
$os_array = explode(")",$user_agent_array[1]);
$os = str_replace('_','.',$os_array[0]); //
$os_version = preg_replace("/[^\d.]/", '', $os); //10.10.5
if(array_key_exists(1,$os_array)){
if($os_array[1] !== ''){
$webkit_array = explode(" ",$os_array[1]);
}else{
$webkit_array = '';
}
}else{
$webkit_array = '';
}
if($webkit_array == ''){
$web_kit = '';
}else{
$web_kit = $webkit_array[1];
}
/*================================
= Browsers =
================================*/
if(array_key_exists(2,$os_array)){
if($os_array[2] !== ''){
$browsers = explode(")",$os_array[2]);
}else{
$browsers = '';
}
}else{
$browsers = '';
}
if($browsers == ''){
$browser_array = '';
$chrome = '';
$safari = '';
}else{
$browser_array = explode(" ",$browsers[0]);
$chrome = $browser_array[1];
if(array_key_exists(2,$browser_array)){
$safari = $browser_array[2]; //bug
}else{
$safari = '';
}
}
//Agent
$agent_os_array = explode("(",$user_agent_array[0]);
$agent = $agent_os_array[0]; // Mozilla/5.0
$device = $agent_os_array[1]; // Macintosh
// Check for existing
$validator = Visitor::validator($ip);
if ($validator->fails()) {
$ip = Visitor::where('ip', '=', $ip)->firstOrFail();
$id = $ip['attributes']['id'];
if($ip){
$visitor = Visitor::findOrFail($id);
$visitor->visit_count = $visitor->visit_count + 1 ;
$visitor->save();
}
} else {
$visitor = new Visitor;
$visitor->ip = $ip;
$visitor->host_name = $host_name;
$visitor->city = $city;
$visitor->region = $region;
$visitor->country = $country;
$visitor->loc = $loc;
$visitor->org = $org;
$visitor->postal = $postal;
$visitor->static_map_url = $static_map_url ;
$visitor->map_url = $map_url ;
$visitor->address = $formatted_address ;
$visitor->details = $place_id;
$visitor->user_agent = $agent;
$visitor->visit_count = $visitor->visit_count + 1 ;
$visitor->device = $device;
$visitor->os = $os;
$visitor->os_version = $os_version;
$visitor->browser_type = $agent;
$visitor->chrome = $chrome;
$visitor->safari = $safari;
$visitor->web_kit = $web_kit;
$visitor->inet = $inet;
$visitor->bssid = $bssid;
$visitor->save();
}
//dd($visitor);
Debug::console($loc);
if(
$visitor->country == 'US' AND
$visitor->ip != '76.119.248.198'
// $visitor->ip != '72.22.171.98'
// AND substr($visitor->host_name) != 'crawl-'
// AND substr($visitor->host_name) != 'spider'
){
//Send Email to me
$mail = Mail::send('layouts.share.emails.site_visit',
array(
'ip_info_array' => $ip_info_array,
'header_info' => $header_info,
'formatted_address' => $formatted_address,
'static_map_url' => $static_map_url
) ,
function ($ip_info_array) {
$ip_info_array->from(env('MAIL_USERNAME') , 'bheng gmail');
$ip_info_array->to(env('MAIL_TO') , 'User\'s Site ')
->subject( ' Visit Alert : ' . Request::server ("HTTP_HOST"));
});
//Send Text Message to me, use the forward from the mail client, so we don't put weigh on the application index
}
?>
I kept getting
How would one go about debugging this further?
I know for sure I have that Visitor
model, I also know for sure I have records on visitors
table in my database.
Upvotes: 1
Views: 568
Reputation: 3455
First, put your whole programming into a controller. To not mix views and controllers. Therefore you've got the possibility to extract functions, methods and what ever calculating stuff into a controller.
But this won't be the solution. That is only an advice for increasing readability of your code.
Since you are upgrading your laravel version you should look for the changelogs. Maybe some functionality is depricated or has been removed.
Finally you should successively reduce your code to find out where the error occurs. Initially remove everything except the static HTML. For example by dd()
or die()
. Then move this function (dd
or die
) further down the code.
If the error remains in the same place, you should see if use ...;
is even legitimate in a .blade.php
. If so, then it should work with standard libraries. So choose something that Laravel natively provides anyway. Anything but your own libraries. After that, it's best to see if there aren't any bugs in one of your libraries. Read the error message carefully to the end. At best, copy it out and post it here in your question.
Additionally import App\Visitor
and App\CURLexec
not in one sentence. Devide them into two imports:
use App\Visitor;
use App\CURLexec;
Upvotes: 1