Search code examples
phpmysqllaravelvar-dump

Laravel: retrieving data from a select statement


I Tried retrieving my data from $result via:

$result->pluck('request_time');

and

$result->request_time;

Both give me a non-object error, var_dump returns:

array (size=1)
  0 => 
  object(stdClass)[167]
  public 'id' => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=38)
  public 'request_time' => string '2015-05-10 17:01:02' (length=19)
  public 'account_id' => int XXXXXXX
  public 'NOW()' => string '2015-05-14 02:03:12' (length=19)

How do I retrieve the data without using the DB::table->pluck method?


Solution

  • It's giving you a non-object error because $result is an array.

    Try $result[0]->request_time;