MAX and MIN Functions in CakePHP 3

0

I'm trying to perform a search on the database that returns the smallest and greatest value of the 'time' field using the following code in CakePHP 3:

$pedidos = TableRegistry::get('Pedidos');
$hora_max = $pedidos->find('list', array('fields' => array('MAX(hora)  AS 'hora_maxima')));
$hora_minima = $pedidos->find('list', array('fields' => array('MIN(hora)  AS 'hora_minima')));
debug($hora_maxima);

However it returns me the following error:

  

syntax error, unexpected T_OBJECT_OPERATOR.

Could someone please help me?

    
asked by anonymous 27.08.2016 / 06:10

1 answer

3

Looking superficially and considering the error message,

syntax error, unexpected T_OBJECT_OPERATOR

You have one more quote:

'MAX(hora)  AS 'hora_maxima'

Correct by removing the middle quotation mark:

'MAX(hora)  AS hora_maxima'

Example:

$hora_max = $pedidos->find('list', array('fields' => array('MAX(hora)  AS hora_maxima')));

Note that the same thing happens in the MIN () assembly:

'MIN(hora)  AS 'hora_minima'
               /\
              /  \
               ||
               ||
    
27.08.2016 / 08:36