Господа подскажите, как оптимизировать такой код:
public function viewsApplication()
{
$applications = array(); $i = 0;
foreach (Application::all() as $application)
{
$applications[$i]['id'] = $application->id;
$applications[$i]['qty_tickets'] = $application->qty_tickets;
$applications[$i]['amount'] = $application->amount;
$applications[$i]['status'] = $application->status;
foreach (Tour::where('id','=',$application->tour_id)->get() as $tour)
{
$applications[$i]['tour'] = "Рейс №".$tour->id.". ".$tour->departure." ".$tour->arrival.". ".$tour->departure_date."-".$tour->arrival_date;
}
foreach (Client::where('id','=',$application->client_id)->get() as $client)
{
$applications[$i]['client'] = $client->surname." ".$client->name." ".$client->patronymic;
$applications[$i]['phone'] = $client->phone;
$applications[$i]['email'] = $client->email;
}
$i++;
}
return view('pages.application.views')
->with(array('applications' => $applications));
}
И накидайте источников, про правильную структуру и форматирования кода.
Спасибо.