Where clause takes too long

I'm using Laravel 5.6

My model is normal

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class MyTable extends Model
{
    protected $table = 'myTable';
    public $timestamps = false;

}

I am trying to make a simple query where it is to bring up 8 Records

I'm using like this:

 public function getDevice( Request $request  ){
        $ip = $request->input('ip');       
        $table = MyTable::where('description', $ip );
        echo "<pre>";
        print_r($table );
        echo "</pre>";
        /*
        return response()->json($table);
        */
    }

But it is crashing and not bringing the result

Consider table

id | description| status | 
1  |  1         |   0    |
2  |  1         |   1    |
3  |  1         |   0    |
4  |  1         |   1    |

But if I use it like this

$query DB::select('SELECT * FROM myTable WHERE description = ?', [1]);

Or if you bring only one

$table = MyTable::find(1); 

$table = MyTable::all(); 

Works

Author: adventistaam, 2018-09-25

1 answers

The way you are using the query is only being stored, not executed. If you really want to run the query, you should use commands like find or get. Try changing the following code

$table = MyTable::where('description', $ip );

For that

$table = MyTable::where('description', $ip )->get();

 4
Author: JrD, 2018-09-26 12:39:23