mardi 25 septembre 2018

No query results for model [App\Model] on Laravel

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>Bunlong Heng</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="Bunlong Heng">
<meta name="csrf-token" value="">


<!--[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') , 'Bunlong\'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

enter image description here


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire