Clause Where takes too long

Asked

Viewed 133 times

1

I’m wearing the 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’m trying to make a simple query where is to bring 8 records

I’m wearing it 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’s catching up and it’s not bringing the result

Consider the table

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

But if I wear 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

  • have tried using single quotes? $query DB::select("SELECT * FROM myTable WHERE description = '?'", 1);

  • That way it works, but that way $table = MyTable::where('description', $ip ); doesn’t work

1 answer

4


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 to change the following code

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

for that

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

  • Carambaaa!! I really had forgotten this detail

Browser other questions tagged

You are not signed in. Login or sign up in order to post.