Object of class Illuminate\Database\Eloquent\Builder could not be converted to string

Posted 4 months ago by TimeSocks

I have a simple table with a temperature and a created_at column. I'm trying to grab all the temperatures recorded in the last 24 hours to pass to charts.js. I have the following function right in my web route:

Route::get('api/temperature', function() {
  return Temperature::where('created_at', '>=', Carbon::now()->subDays(1)->toDateTimeString())
    ->selectRaw('strftime("%h",created_at) as hour, temp as temperature')
    ->groupBy('hour');
});

But this gives me the error:

Object of class Illuminate\Database\Eloquent\Builder could not be converted to string

What gives?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.