I don't know if this is possible in symfony, that is getting the last array when using respository. In my controller a have this function
/**
* @param $id
* @return Food
*/
public function getFood($id)
{
$em = $this->getDoctrine()->getManager();
$food = $em->getRepository("AppBundle:Food")->findById($id);
if (!$food) {
throw $this->createNotFoundException("Invalid Food");
}
return $food;
}
this will show the single food that I need. In my repository I have this code
/**
* Display Food and get the last transaction
* @param $id
*/
public function findById($id){
$query = $this->createQueryBuilder(f)
->where('f.id = :id')
->setParameter('id', $id)
->getQuery()
->getResult()[0];
return $query;
}
This code successfully displaying the data of food Foods
- id
- name
- price
- packages
- id
- name_package
- category
- User
- id
- username
- password
- email
- transaction []
1 - {
- id
- date
- emailStatus
- email
}
2 - {
- id
- date
- emailStatus
- email
}
3 - {
- id
- date
- emailStatus
- email
}
How can I get the last transaction of food? I just want to display the last part of transaction that is like this one.
update
- id
- name
- price
- packages
- id
- name_package
- category
- User
- id
- username
- password
- email
- transaction []
3 - {
- id
- date
- emailStatus
- email
}