-2

Hello I'm very new to Laravel and PHP so sorry if this question is stupid. I need to display data from my ping controller where I am getting ip adresses from db. But my page is empty. Any suggestions?

    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

     class ping_controller extends Controller
{


public function ping()
{
    $iplist = \DB::table('pc_ip')->where('id')->get();
    $ipcount = $iplist->count();

    $IP =[];
    for($i=1;$i<=$ipcount;$i++)
    {
        $IP['ip_adress'] = DB::table('pc_ip')->get($i);
        exec("ping -c 1 " . $IP . " | head -n 2 | tail -n 1 | awk '{print $7}'", $ping_time);
        if($ping_time <1000)
            {

                echo("PC $IP is active");
            }
        else
        {
            echo("PC $IP is inactive");

        }
    }




}
}
  • Did you create a web route? If so, show it. – Cory Fail Nov 19 '18 at 21:32
  • 1
    Don't rely on `echo`; it's useful for showing information, but Laravel is an MVC, Model, View, Controller. You have a Controller, now you need it to return a view. Your Model is currently the result of `\DB::table("pc_ip")`, where it could be an actual Model of `PCIP`, but that's a tangent. Look into how to return a view in Laravel: https://laravel.com/docs/5.7/views – Tim Lewis Nov 19 '18 at 21:32
  • Route::get('/ping', 'ping_controller@ping')->name('ping'); – Jakub Skurčák Nov 19 '18 at 21:33
  • Make sure the `/storage` folder is writable by the webserver. If you have an error and this folder is not writable, you get a blank page. – Jerodev Nov 19 '18 at 22:08
  • Possible duplicate of [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – miken32 Nov 19 '18 at 22:22
  • Never `echo` from a controller. You want to return the data you need to display. – jfadich Nov 19 '18 at 23:44
  • Reserve capitalized variables for constants. Advise to change `$IP =[];` to `$ip = []` – Diogo Santo Nov 20 '18 at 01:09
  • I do not understand why you have this? I am also not aware of your DB planning so I am conscious you might need this `\DB::table('pc_ip')->where('id')->get();` but id should always exist as well, so I would advice to change it to `\DB::table('pc_ip')->all();` at same time I advise the same as @TimLewis. You should have a Model for it – Diogo Santo Nov 20 '18 at 01:11

1 Answers1

0

I think these might help, 1. Check your route if it is directed to your ping_controller, 2nd used dd() instead of echo.

Ex.

public function ping(){ dd('welcome to my page'); }

Just to check that you're calling a correct route. Hope it help.

Dominique
  • 9
  • 2